The command does not work in the script, but it works in the shell

I am writing a script to use SSH profiles, ~ / scripts / ssh-profiled.sh

PROFILE=`cat ~/script/ssh-profiles/$1` echo [ssh $PROFILE] ssh $PROFILE 

~ / scripts / SSH profiles / tummi

 -i ~/Dropbox/security/key-nopass/key-nopass.pvt bart@example.com 

When I run the script, it fails:

 bart@bart-laptop :~$ script/ssh-profiled.sh tummi [ssh -i ~/Dropbox/security/key-nopass/key-nopass.pvt bart@example.com ] Warning: Identity file ~/Dropbox/security/key-nopass/key-nopass.pvt not accessible: No such file or directory. bart@example.com password: 

But it works:

 bart@bart-laptop :~$ ssh -i ~/Dropbox/security/key-nopass/key-nopass.pvt bart@example.com Linux tummi 2.6.32-24-server #39-Ubuntu SMP Wed Jul 28 06:21:40 UTC 2010 x86_64 GNU/Linux Ubuntu 10.04.1 LTS Welcome to the Ubuntu Server! 

Is there a / gotcha error in my script?

+4
source share
4 answers

Change the first line to

 eval PROFILE=`cat ~/script/ssh-profiles/$1` 

For an explanation see here

+5
source

~ in your file should be the full path to the home directory, it does not expand.

+2
source

My hunch is that "~ /" is not interpreted as expected when passed this way. Try using an explicit full path.

+1
source

What are the permissions for the .pvt file? If only you have read access and no one can execute it, then your script may not even see the file. Perhaps this is why you get the message "...not accessible: No such file or directory." .

0
source

Source: https://habr.com/ru/post/1333736/


All Articles