Visit Our UNIX and Linux User Community


IF condition failing in a SSH script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting IF condition failing in a SSH script
# 8  
Old 11-20-2007
Thanks everybody for your valuable inputs .

Quote:
I think that since ssh is non-interactive (not a controlling terminal) You can't have a terminal like session,

Yes, that explains everything. SSH session is non interactive, so I can't expect a TEST condition to work within that ssh session.

Quote:
Do You even get a prompt for answer to Your read statement?

Nope !

And I thought about having the TEST condition OUT of the ssh session,( where everything works fine ), but I was trying to avoid multiple logins to the machine, and it seems that there's no escape. (Well, you can export the public/private keys to have a passwordless login to other machines, but there are situations where you can't always do that).

Anyway, better knowing how the things are, than spending days trying to figure out why it doesn't work the way you expect it to work.
# 9  
Old 11-20-2007
Why not do it in multiple stages?
Code:
scp my.sh user@host:
ssh user@host ~/my.sh
ssh user@host /bin/rm ~/my.sh

My experience with sshd is that running commands directly (like the my.sh example above) does not guarantee you'll have your environment set up, so define PATH in your script or use full path names.
# 10  
Old 11-21-2007
Quote:
Originally Posted by LivinFree
Why not do it in multiple stages?
Code:
scp my.sh user@host:
ssh user@host ~/my.sh
ssh user@host /bin/rm ~/my.sh

My experience with sshd is that running commands directly (like the my.sh example above) does not guarantee you'll have your environment set up, so define PATH in your script or use full path names.
Very good point, and I do it a lot. Especially the benefit You get from always feeding Your script to the recipient is that the original is held at the server/controlling host and if You do any edits, it will always be used next time on the remote. And always make sure what environment You want for the running script. But the solution depends on what You want from the remote host, how often it's done etc.

/L

Previous Thread | Next Thread
Test Your Knowledge in Computers #660
Difficulty: Medium
DOS uses a filesystem which supports 9.3 filenames: 9 characters for the filename and 3 characters for the extension.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SSH is failing due to unknown reason

Hi, I have setup keys between user1@server1 and user2@server2 however, the ssh is failing. server1 is Linux 3.10.0-514.6.2.el7.x86_64 #1 SMP whereas server2 is 5.10 Generic_150400-40 sun4v sparc sun4v I have checked port 22 to be open and keys to be correct. I also find the permissions... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

Ssh failing due to Bad owner error

i am logged in with "user1" on host1. I m trying to ssh to host2 using user id "user2" $ ssh user2@host2 Bad owner or permissions on /home/user1/.ssh/config Question 1: Can you please tell me why am i getting the Bad owner permissions error on that directory ? Question 2: Where is it... (7 Replies)
Discussion started by: mohtashims
7 Replies

3. Shell Programming and Scripting

Writing if condition in shell script and failing to do requirement

Hi, I am trying to edit the values in a file. For example i am trying to edit the value of "ABC" in a file by executing shell script. Please Note that ABC value can be there mulitple times or it may not be there in the file Conditions for it is 1. If ABC is less than 123 then it should... (14 Replies)
Discussion started by: darling
14 Replies

4. UNIX for Dummies Questions & Answers

Crontab script failing

Hello, A crontab script is failiing everyday but when we execute manually it runs fine Below is the script scheduled: 00 23 * * * sh /db2backup/scripts/db2_hot_backup.ksh TRAVFF > /dev/null 2>&1 Error: cat TRAVFF_online_04022014_2300.log Started : Wed Apr 2 23:00:00 EDT 2014... (2 Replies)
Discussion started by: Vishal_dba
2 Replies

5. Shell Programming and Scripting

Connect (SSH) to Windows server via Linux server through a script and passing command.. but failing

I am trying to connect to Windows server via Linux server through a script and run two commands " cd and ls " But its giving me error saying " could not start the program" followed by the command name i specify e g : "cd" i am trying in this manner " ssh username@servername "cd... (5 Replies)
Discussion started by: sunil seelam
5 Replies

6. UNIX for Advanced & Expert Users

SSH public key failing without error message

My password-free ssh connection has worked in the past but has stopped working and I can't get it going again. The files in .ssh on both source and target are set to 600: drwx------ 2 ingres 1024 Mar 2 13:57 . drwxr-xr-x 25 ingres 2048 Mar 29 09:38 .. -rw------- 1 ingres ... (9 Replies)
Discussion started by: Catullus
9 Replies

7. Shell Programming and Scripting

SCP Failing - In Script

I create a file that may contain several full path name files on a remote Linux that are to be copied. This file, called AWKOUTPUT is created from another script. It contains: X/picture1.png The script is very simple ------------------------------------------- REMOTEDIR="/var/CC/Stuff"... (4 Replies)
Discussion started by: mohrsville12
4 Replies

8. Shell Programming and Scripting

Expect script help needed- script failing if router unavailable

Hey all. Sometimes I'm tasked to change some router configs for the entire network (over 3,000 Cisco routers). Most of the time its a global config parameter so its done with a loop and an IP list as its the same configuration change for all routers. This is working OK. However, sometimes an... (3 Replies)
Discussion started by: mrkz1974
3 Replies

9. Shell Programming and Scripting

Using ssh to transfer file not working inside if-condition

Hi all, ssh uname@remote_server 'cat /tmp/remote_file_name > home_dir/a512386/new/local_file_name' The above given command is working fine. but if i try to move the file only if exists in the remote server i.e) giving the same within if condition it executes but the file is not stored in my... (1 Reply)
Discussion started by: Shri123
1 Replies

10. Shell Programming and Scripting

ssh - rm failing

Hi, Please help me... I am creating a string of filenames with absolute path and deleting those files situated in the remote server using ssh .. but it doesnot work.. Can anyone help me... here is my code for FileName in ${myDire} do Tmp=`basename... (4 Replies)
Discussion started by: shihabvk
4 Replies

Featured Tech Videos