Bart van Heukelom
Bart van Heukelom

Reputation: 44084

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?

Upvotes: 4

Views: 2401

Answers (4)

bakoyaro
bakoyaro

Reputation: 2558

What are the permissions on the .pvt file? If only you have read access, and no one can execute it, then your script might not be able to even see the file. That could be why you are getting the "...not accessible: No such file or directory." message.

Upvotes: 0

Victor Sorokin
Victor Sorokin

Reputation: 11996

Change 1st line to

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

For explanation see here

Upvotes: 5

ergosys
ergosys

Reputation: 49009

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

Upvotes: 2

Scott Waddell
Scott Waddell

Reputation: 11

My guess is the "~/" is not being interpreted as expected when passed in that way. Try using an explicit full path.

Upvotes: 1

Related Questions