I'm writing a script where Cygwin needs to cp a file from my desktop.
cp /cygdrive/c/Users/<username>/Desktop/file /tmp/file
How can I make Cygwin get my or the username of the person who is currently running it?
I found it in a different answer,
The profile of the current user is $USERPROFILE.
Putting them together it becomes:
cp $USERPROFILE/Desktop/file /tmp/file
Related
I have currently put together a script to move files from one directory to another.
This has gone ok however I was wondering if there was a way via a shell script to get it to run from anywhere on the server e.g I give the script for someone to use on their server and they can put the script anywhere and it will run.
I know a workaround is to put the script in /usr/local/bin or usr/bin and you can run it from anywhere but that is not what I want.
Is there a way that my script will auto run from usr/local/bin regardless of if it is in /scripts for instance?
Please see my script below:
#!/bin/sh -x
mkdir -p /var/Alitest
echo "This is a test that I have created. This is to
see if the output is successful I normally do this manually but a script is required" > /var/Alitest/action.txt
sed -i 's/This is a test that I have created/The test has been successful/g' /var/Alitest/action.txt
chmod 744 /var/Alitest/action.txt
chown root:root Alitest/action.txt
mv /var/Alitest/action.txt /script/action.txt
Any help would be greatly appreciated :)
Also in my log output for the script the following error is shown:
sed: 1: "/var/Alitest/action.txt": invalid command code A
Any ideas?
You can make a soft link in /usr/local/bin for your script. Then it will be in everyone's path to be executed.
e.g. ln -s /script/yourscript.sh /usr/local/bin/yourscript.sh
After reviewing the matter further I have decided the the best way to action this is to add the folder destination e.g /scripts to my path.
This can be done by vimming into the .bashrc file on the server and adding the below line:
export PATH=/dir_name:$PATH
remember to refresh the profile in order for the changes to take effect.
You can check if this has been successful by running the below command:
echo $PATH
There is no way to get your script to do this however this would be better then a softlink as if you add it to $PATH then you do not have to go through the task of adding softlinks each time.
Thank you all for your help.
Kind Regards
Ali
I am trying to send a file or folder to Desktop with Linux Command Prompt but I don't know how.
Please tell me what command can I use for this?
The move command mv. Use man mv for more information, as this command is a lot more complex than it seems. With cd Desktop/ you should be able to find your desktop on variations of linux like Mint or Ubuntu. To find your present working directory, as in your current path for the terminal, type pwd. This will give you your directory which will be similar to /home/Desktop.
Wasn't quite sure how to word this but let's say I've used ssh to remote into my friends MacBook (macbook_b) from my MacBook (macbook_a).
What command would I use to copy a file/directory to my MacBook (macbook_a) from my friends MacBook (macbook_b)?
Thank you.
You can use scp (Secure Copy).
To copy FROM your machine to friends:
scp file_to_copy user#remote.server.fi:/path/to/location
In another direction:
scp user#remote.server.fi:/path/locatio/file_name file_name
If you need to copy an entire directory, you'll need to use the recursive flag, like this:
scp -r directory_to_copy user#remote.server.fi:/path/to/location
Assuming you're logged in on macbook_b:
scp file_to_copy username#macbook_a:/path/to/destination
or if you're logged in on macbook_a:
scp username#macbook_b:/path/to/file_to_copy local_destination
I think this link would help you with the answer you are looking for. In this you can use scp ssh source destination example for your scenario you have requested for.
Also refer to this question which has been already answered. It might help.
first do pwd to get the path to the file of your friends macbook then
go into your machine's ssh window and do
scp user_name#machine_name(of your friend's):(copy the path after executing pwd)/file_name .(dot means your your current directory)
enter his password !
voila !!!
I have a set of files in my ftp folder. I have access to only ftp mode. I want to rename those files with extension .txt to .done
Ex:
1.txt, 2.txt, 3.txt
to
1.done, 2.done, 3.done
Only rename command is working in this ftp. I am expecting something like
rename *.txt *.done
to rename them all in a single command.
In short: You can't.
FTP is very basic and does not support mass renaming. You can either write a small script for it, or download some helper software, such as the one here.
Hallo to all,
Even if the question is quite old, I think could be usefull for others to read my suggestion.
I found a great and easy solution combining curlftpfs, "A FTP filesystem based on cURL and FUSE" as they define it, and rename linux and unix multi rename tool.
I tested on linux mint 17 (and I think it should work in other debian based distributions)
install curlftpfs
sudo apt-get install curlftpfs
create the mount folder
sudo mkdir /mnt/ftp_remote_root
mount remote ftp on folder
sudo curlftpfs -o allow_other -o user="USERWITH#CHARACTERTOO:PASSWORDTOACCESSUSER" ftp://my_ftp_server.com /mnt/ftp_remote_root/
jump into desired ftp remote folder
cd /mnt/ftp_remote_root/path/to/folder
rename as you need files (-v shw new names, -n show interested files, omitt them to rename files)
sudo rename -v -n 's/match.regexp/replace.regexp/' *.file.to.change
It could took few seconds because it works on network.
I think it is really powerfull and easy to use.
Let me know if you find any problems.
Bye
Lorenzo
try something like this:
the following example move/rename files on the FTP server
for f in $(lftp -u 'username,password' -e 'set ssl:verify-certificate
no; ls /TEST/src/*.csv; quit' ftp.acme.com| awk '{print $9;}'); do
lftp -u 'username,password' -e "set ssl:verify-certificate no; mv
/TEST/src/$f /TEST/dst/$f; quit" ftp.acme.com; done
note: use .netrc to store username and password.
Use the following command:
ren *.txt *.done
#!/bin/bash
"mirror -R //thevault/Shared/Operations/Marketing/test --only-missing -e ;exit"
I'm using lftp to mirror a folder on a share drive. But it fails with "No such file or directory" What's the correct way to write this? and How would I escape a space in the file name. I've tried literally everything.
I've also tried /cygdrive/s/Operations/Marketing/test. This works while I'm logged in and I run the script. But when the task is run while I'm not logged in the log file I get the same "No such file" Error.
I don't think that is support in general in cygwin for UNC pathnames (ie \\server\share) so you'll have to rely on mapping to a network drive and then using /cygdrive/s. To fix the problem with it not working when you aren't logged in, you'll need to call the Windows NET program from your script:
net use s: \\thevault\Shared password /user:myuser
There may be some security implications to having the password in plaintext, so another possibility is to ensure that the script is running from a user account that has read permission to this server, and then you can omit the password.
This seems to be working perfectly while logged out.
#!/bin/bash
lftp ftp://username:password#server.com -e "mirror -R //thevault/Share/folder/folder/folder\ with\ spaces/folder/folder --only-missing -e;exit"
It was the escaped spaces in my path. The reason that this didn't work is because when I retyped the path I misspelled share. //thevault/shared <~~ incorrect
#!/bin/bash
"mirror -R //thevault/Shared/folder/folder/test --only-missing -e ;exit"