prevent ssh from executing result in shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting prevent ssh from executing result in shell
# 1  
Old 01-21-2010
prevent ssh from executing result in shell

Hi,

I am writing a script on Solaris 10 and want to execute a remote ssh command. Normally this command should just return the value 0000000000002356 but when using ssh it seems it is passing the result to the shell to execute.

Code:
ssh root@10.5.112.145 `/usr/bin/nawk -F\, '$1=="USG" && $2=="01" && $3=="20" && $4=="2010" { print $11 }' /var/log/usage/lic.log | sort -rn | head -1`
sh: 0000000000002356: not found

I have tried various backticks and quotes to escape this but can't. Ssh here documents dont seem to work on Solaris...

Code:
bash-3.00# ssh root@10.5.112.145 <<EOF /usr/bin/nawk -F\, '$1=="USG" && $2=="01" && $3=="20" && $4=="2010" { print $11 }' /var/log/usage/lic.log | sort -rn | head -1 EOF
>


Last edited by pludi; 01-21-2010 at 02:59 PM.. Reason: code tags, please...
# 2  
Old 01-21-2010
Yes, the first part tries to run the command "0000000000002356", but on the remote host. If you'd use regular quotes (') instead of backticks (`) the nawk command will be sent to, and executed, on the remote host. Until then, it's executed locally, and the result give to ssh to run elsewhere.

As for your second question: yes, ssh ignores pipes and here-docs for security reasons. Anything sent in that way will only be piped to a command running on the remote host, but never in an interactive session.
# 3  
Old 01-21-2010
Thanks for that pludi,

So what can I do then?

I can't use normal quotes because they are required in the nawk command that I want to run. I have tried escaping them but it doesnt work.
# 4  
Old 01-21-2010
Power workaround

Quoting and ssh: this is really painful, and your mileage will vary depending on used shell and ssh setup.

I found piping to be a usable workaround though. You may try something like this:

Code:
> cat > ./tmp.sh
awk -F: '{ print $1 }' /etc/passwd
^D
> ssh localhost < ./tmp.sh
Pseudo-terminal will not be allocated because stdin is not a terminal.
Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell.
root
bin
daemon
adm
lp
sync
...


The errors/warning in the beginning are annoying of course - but you can remove them with

Code:
> ssh localhost < tmp.sh |& tac | head --lines=-3 | tac

Ugly, I know. You can also play with the -T and '-t -t' options of ssh - in some setups that seems to help.

I'd be happy if someone else knows a better solution :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing multiple ssh commands inside a shell simultaneously

I would like to execute a commands in four different servers through ssh at a single instance(simultaneously). Below are the details with examples, ssh user1@server1 "grep xxxx logs" ssh user1@server2 "grep xxxx logs" ssh user1@server3 "grep xxxx logs" Each statement will take some... (4 Replies)
Discussion started by: Amutha
4 Replies

2. UNIX for Dummies Questions & Answers

tcsh: how to prevent a foreach from terminating a script when the result is null?

Sorry if this has been answered. I did search both Google and this site and did find this post: unix.com/unix-dummies-questions-answers/152992-how-ignore-errors-script.html However, it wasn't answered. I have the same question - how do you prevent a tcsh script from terminating when the... (4 Replies)
Discussion started by: deepstructure
4 Replies

3. Shell Programming and Scripting

Executing the result of a program as a shell script

I have a program that returns a shell script and I want to execute the script. I'll use cat in my simple example, but wget is an example that is feasible. $ # First setup a script $ echo "ls > df" > simple $ # "cat simple" is now a program that returns a script $ cat simple ls df $ ... (3 Replies)
Discussion started by: kopite
3 Replies

4. Shell Programming and Scripting

executing command in a remote machine through ssh - shell script

Hi All, i have two machines like x and y . my requirement is i should connect to machine Y from x through ssh connection . and do some operation such as copy and move and delete files in Y machine . i tried with this code but it is doing in machine x only . and i need to exit from Y when... (1 Reply)
Discussion started by: rateeshkumar
1 Replies

5. UNIX for Dummies Questions & Answers

how to stay in remote shell after executing commands in ssh?

the ssh calling convention: ssh <server> If I put commands in the section, ssh will execute them immediately after logging in and return to local shell. I want to stay in the remote shell after executing these commands. How can I achieve this? Thanks for all. (1 Reply)
Discussion started by: hplonlien
1 Replies

6. UNIX for Dummies Questions & Answers

Force user to use ssh/prevent telnet access

I have just set up a user on our system HP-Thru64. The user needs to be able to su to root after they login and this works fine. Users cannot login from root externally so you have to first connect as a user and then su. I am wondering is it possible for me to prevent the user from having telnet... (4 Replies)
Discussion started by: peragin
4 Replies

7. UNIX for Advanced & Expert Users

transporting scripts onto sloaris, executing it and returning the result to windows

Hi, I have to write a windows XP program, that would generate a Solaris Script, which would then be transported to Solaris, executed, the execution result then needs to be returned to the XP program. For transporting the file i was thinking of following FTP (admins rejected it) or File share on... (1 Reply)
Discussion started by: 00262881
1 Replies

8. UNIX for Dummies Questions & Answers

meaning of columns in the result of executing 'ls -l'

Hello all, I do not understand the meaning of some columns in the result of executing 'ls -l'. For example, i got the following result by run 'ls -l' total 3531 -rw-r--r-- 1 root root 1351680 Oct 17 20:50 fileindex.rpm -rw-r--r-- 1 root root 16384 Oct 17 20:50 groupindex.rpm ... (5 Replies)
Discussion started by: cy163
5 Replies

9. UNIX for Advanced & Expert Users

executing script by cron doesnt give me expected result

Hi frnds... I m facing very irritating problem already waisted my 2 days.. I have a following script..( i am pasting only the main code) ftp -ivn 213.194.40.77 <<FTP user $user $password binary cd $FileDir/out lcd $localpath get $file rename $FileDir/out/$file $FileDir/tmp/$file... (1 Reply)
Discussion started by: clx
1 Replies

10. Cybersecurity

SSH - prevent roaming around the server

Hi, We have a user who needs to connect to us over the internet using an ssh client. We use HP-UX 11.00. We set up a home directory with login and password for them. We would not want to give them full roaming access for the server ie, they should not be able to cd up the directory tree. ... (2 Replies)
Discussion started by: Bab00shka
2 Replies
Login or Register to Ask a Question