Sponsored Content
Top Forums Shell Programming and Scripting [Solved] While read line and if statement not working Post 302851741 by whegra on Monday 9th of September 2013 02:42:46 PM
Old 09-09-2013
[Solved] While read line and if statement not working

I'm looking for some help in figuring why my little bit of code will not process any entries other then the first one in my list.

Code:
while read line ;do
        hostname=${line//\"}
        a=`ssh user@$hostname uptime;echo $?`
        if [[ "$a" = "255" ]];then
                dt=`date`
                touch /home/user/email.txt
                echo "To:user@userdomain.com" >> /home/user/email.txt
                echo "Subject: URGENT - $hostname is down" >> /home/user/email.txt
                echo "Content-Type: text/plain" >> /home/user/email.txt
                echo "X-Priority: 1 (Highest)" >> /home/user/email.txt
                echo "X-MSMail-Priority: High" >> /home/user/email.txt
                echo "Connection Failed at: $dt" >> /home/user/email.txt
                /usr/sbin/sendmail -t < /home/user/email.txt
                rm -f /home/user/email.txt
        fi
        rm -f /home/user/email.txt
done < "/home/user/servers.txt"

It connects to the first server in the list just fine, but will not try the 2nd or 3rd entry in the servers list.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

read statement not working in a function

Pls this is emergency.I have written a script which is taking input from another script. and the contents of my second script are acting as functions to my main script.Now the problem is that in one of the functions i want the script ececution to stop and start when user enters any character r... (2 Replies)
Discussion started by: sumitdua
2 Replies

2. Shell Programming and Scripting

Read statement not working in a script

I have a script consisting of certain functions whose input is a file at same location. In that file i have written the name of anothe file at same location. The third file contains a word which act as a function in the first script.Let me give an example i have a scrip file say 1.sh in which i am... (7 Replies)
Discussion started by: sumitdua
7 Replies

3. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

4. Shell Programming and Scripting

[Solved] Read a line from one string till to another.... Unix scripting..

So i have a file which contains paths to JPG images separated by a space. I have to separate them each path to another file. So, I have to search all strings that start from /home/ and ends with .jpg or .png Then write each one to another file... Can you please help me on doing this???:cool: (11 Replies)
Discussion started by: hakermania
11 Replies

5. Shell Programming and Scripting

[Solved] Read a .gz file line by line without using gzcat

Hi all Is there a way to read and process a gzip file line by line similar to a text file without using gzcat.. while processing a text file we will usually use the logic exec<sample.txt while read line do echo $line done Is there a similar way to process the gz file in the same... (4 Replies)
Discussion started by: aikhaman
4 Replies

6. Shell Programming and Scripting

While loop read line not working

Hi, I am trying to read a file line by line inside of a while loop. This while loop is part of a here document. while read line do ssh -t $2@$remotehost <<REMOTE ls path/to/dir > $path_to_dir while read line1 do echo "LINE --- $line" done... (4 Replies)
Discussion started by: mnanavati
4 Replies

7. Shell Programming and Scripting

[Solved] Not able to read the next line from a file after doing ssh

Hi, I am trying to write a code, where it reads the jobnames from a file and checks for the logs in the server. If the log is not found in the first server, then it will ssh to the 2nd server and get the details from there. I will need to save the date in a variable. But the problem is that,... (0 Replies)
Discussion started by: ajayakunuri
0 Replies

8. Shell Programming and Scripting

Read statement not working

hello guys, i am having the below piece of code error () { echo"Press y /n" read ans case $ans in y) main;; n) exit esac } In the abve code, read statement is not working i.e not waiting for user to enter input. ,i tested exit status its 1. could anyone help me to do this ... (11 Replies)
Discussion started by: mohanalakshmi
11 Replies

9. Shell Programming and Scripting

While read -a line not working in ksh

while read -a line; this is not working in ksh. what is the equivalent of this in ksh. read: -a: unknown option (2 Replies)
Discussion started by: archana25
2 Replies

10. Shell Programming and Scripting

Bash read input in case statement not working as expected

I'm having an issue with bash read input when using a case statement. The script halts and doesn't read the input on the first loop. if I hit enter then the scripts starts to respond as expected. Need some help here. defaultans=8hrs read -e -i $defaultans -p "${bldwht}How long would you like... (5 Replies)
Discussion started by: woodson2
5 Replies
SSH-KEYSIGN(8)						    BSD System Manager's Manual 					    SSH-KEYSIGN(8)

NAME
ssh-keysign -- ssh helper program for host-based authentication SYNOPSIS
ssh-keysign DESCRIPTION
ssh-keysign is used by ssh(1) to access the local host keys and generate the digital signature required during host-based authentication with SSH protocol version 2. ssh-keysign is disabled by default and can only be enabled in the global client configuration file /etc/ssh/ssh_config by setting EnableSSHKeysign to ``yes''. ssh-keysign is not intended to be invoked by the user, but from ssh(1). See ssh(1) and sshd(8) for more information about host-based authen- tication. FILES
/etc/ssh/ssh_config Controls whether ssh-keysign is enabled. /etc/ssh/ssh_host_dsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_rsa_key These files contain the private parts of the host keys used to generate the digital signature. They should be owned by root, read- able only by root, and not accessible to others. Since they are readable only by root, ssh-keysign must be set-uid root if host- based authentication is used. /etc/ssh/ssh_host_dsa_key-cert.pub /etc/ssh/ssh_host_ecdsa_key-cert.pub /etc/ssh/ssh_host_rsa_key-cert.pub If these files exist they are assumed to contain public certificate information corresponding with the private keys above. SEE ALSO
ssh(1), ssh-keygen(1), ssh_config(5), sshd(8) HISTORY
ssh-keysign first appeared in OpenBSD 3.2. AUTHORS
Markus Friedl <markus@openbsd.org> BSD
August 31, 2010 BSD
All times are GMT -4. The time now is 02:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy