Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command doesn't work in script, but works in shell

I'm writing a script for using 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 [email protected]

When I run the script, it fails:

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

But this works:

bart@bart-laptop:~$ ssh -i ~/Dropbox/security/key-nopass/key-nopass.pvt [email protected]
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 an error/gotcha in my script?

like image 315
Bart van Heukelom Avatar asked Feb 25 '23 12:02

Bart van Heukelom


2 Answers

Change 1st line to

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

For explanation see here

like image 147
Victor Sorokin Avatar answered Feb 28 '23 01:02

Victor Sorokin


The ~ in your file needs to be the full home directory path, it's not getting expanded.

like image 21
ergosys Avatar answered Feb 28 '23 00:02

ergosys