My OS is Ubuntu16 in virtualbox.
I'm trying to write a script to transfer multiple files(filename:t01,t02,t03) with scp.
This is my code:
vim scriptname
#!/bin/bash
for a in {01..03}
do scp -i ~/home/username/.ssh/id_rsa -r t$a
username#xx.xx.xx.xxx:/home/username/Desktop
done
And when I typed this in the terminal
./scriptname
I got this
Warning: Identity file /home/ian/home/ian/.ssh/id_rsa not accessible: No
such file or directory.
t01: No such file or directory
Warning: Identity file /home/ian/home/ian/.ssh/id_rsa not accessible: No
such file or directory.
t02: No such file or directory
Warning: Identity file /home/ian/home/ian/.ssh/id_rsa not accessible: No
such file or directory.
t03: No such file or directory
One thing I couldn't understand is that I actually wrote "/home/ian/.ssh/id_rsa" in the script. But the error message showed "/home/ian/home/ian/.ssh/id_rsa". I have tried to type my ssh_key directory in different ways, such as "/.ssh/id_rsa" but still couldn't work.
What did I do wrong?
Thank you!
t01: No such file or directory
Told you that it cannot access the file
Because the dictionary you run the bash script is not the same to where the files are.
If you want to put files not in the same dictionary, you have to give the full path for all of them.
Related
I am using an ssh account that connects to an external server, i have downloaded through guix some software like samtools and bedtools but when i try to use them in my directory it gives me this error:
-bash: samtools: command not found
In my direcory, however, there is the directry guix.profile and if I go into the bin folder of this, I have everything I downloaded.
What am I doing wrong?
Thank you
enter image description here
To run a file from the shell you need two things:
The shell must find the file
Being in the same directory does not enable the shell to find the file. You have to either supply an absolute or relative path the file, or have the directory in your PATH environment variable
In simplest terms this means instead of
$ samtools
try
$ ./samtools
The relative path tells the shell it wants that file
To run it from another directory, either use the whole absolute path, e.g. /home/yourname/samtools , or move the file into a directory that is on your $PATH
The file needs to be executable
If the file is not executable you will need
$ chmod +x ./samtools
Hello I'm trying to make a simple .bat file, I'm trying to modify a file after downloading it from another machine.
The problem is the python script needs the full name of the file, so filename* won't work so is there a way to download a file via scp and then somehow assign the downloaded file a variable so the script can find the full name
scp user#192.168.1.X:"C:\Users\user\Downloads\filename*" ./
pythonscript.py filename*
pythonscript.py "%cd%\filename"
I am working on a script to copy a custom user profile over to the default. Part of the script uses rsync to copy the contents of the customized profile, named "profile" to the default profile located in: /System/Library/User Template/English.lproj. Each time I run the command interactively, it fails indicating "No such file or directory." I can browse to the directory in the Finder. I can navigate to the directory via the terminal. Why can't rsync find it? Here is the command:
rsync -av /Users/profile/* /System/Library/User\ Template/English.lproj
I tried a similar approach using cp -R instead of rsync and got a whole bunch of file not found error messages. Using the cd command to that same path also fails. I can step through each individual directory and arrive at English.lproj but I can't do it in one command. Any ideas where I am going wrong with my command?
Thanks
Jason
I am using ssh to work on a remote server, however when I try to download a file using scp in this format:
scp name#website.com:somefile.zip ~/Desktop
It asks me for my password, and shows this:
somefile.zip 100% 6491 6.3KB/s 00:00
however, this file never appears on my desktop. Any help
I think that you are logging into the remote machine using ssh and then running the command on the remote machine. You should actually be running the command without logging into your remote server first.
You need to specify the file path
scp name#website.com:/path/to/somefile.zip ~/Desktop
~/Desktop should actually be a directory, not a file. I suggest that you do the following:
Remove the ~/Desktop file with rm ~/Desktop (or move it with mv if you want to keep its contents).
Create the directory with mkdir ~/Desktop.
Try again to scp the zip file.
BTW, when I need to copy files into directories, I usually put a slash after the directory to avoid such problems (in case I make a mistake), e.g. scp server:file ~/Desktop/; if the directory doesn't exist, I get an error instead of unwanted file creation.
You are doing this from a command line, and you have a working directory for that command line (on your local machine), this is the directory that your file will be downloaded to. The final argument in your command is only what you want the name of the file to be. So, first, change directory to where you want the file to land. I'm doing this from git bash on a Windows machine, so it looks like this:
cd C:\Users\myUserName\Downloads
Now that I have my working directory where I want the file to go:
scp -i 'c:\Users\myUserName\.ssh\AWSkeyfile.pem' ec2-user#xx.xxx.xxx.xxx:/home/ec2-user/IwantThisFile.tar IgotThisFile.tar
Or, in your case, (that is with the VERY strong password you must be using):
cd ~/Desktop
scp name#website.com:/path/to/somefile.zip somefile.zip
I created a SCP script where it will take the source directory input from command line, but I see an issue with that, for example, If I want to copy 5 files under /var/lib directory then in my command line If I do /var/lib/* then each file is taken as a separate command line argument and my script fails, I can't even copy the whole lib directory because in destination I do not want that folder to be created. Any idea would help, thanks..!!