Passing file name to get uptimes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing file name to get uptimes
# 8  
Old 03-15-2012
what error message you are getting ?

---------- Post updated at 08:03 PM ---------- Previous update was at 07:58 PM ----------

make sure, your file should have only the servername
This User Gave Thanks to itkamaraj For This Post:
# 9  
Old 03-15-2012
Thanks itkamaraj for the help!

It works partially, i see only the first server with the details in the output file.

The hosts.list file has servers listed in one column like below:

server1
server2
server3
...and so on

Right now, its showing me only the server1 details with the uptime. Can you please help where i can see all 50 servers? Thanks in advance! Smilie
# 10  
Old 03-15-2012
Code:
SERVERS=$(cat /tmp/hosts.list)
for i in $SERVERS;
do 
uptime=$(ssh $i uptime)
echo "$i $uptime" >> output.txt
done

# 11  
Old 03-15-2012
This looks like an DNS issue. You can add an entry of the servers that you are trying to ssh in the /etc/hosts.
# 12  
Old 03-15-2012
Quote:
Originally Posted by hithere30052
Thanks Corona...can you also help me here

the updates you made to the script displays only one row and i wanted all 50 servers to be displayed.
My changes are not working either:

Code:
server_list='/tmp/hosts.list'

for SERVER in $server_list
do
    while read line
    do
    /usr/local/bin/ssh "$SERVER" printf "${server} : " ';' uptime
    done < $server_list
done

Errors i am getting:
Code:
ssh: /tmp/hosts.list: no address associated with name
ssh: /tmp/hosts.list: no address associated with name
ssh: /tmp/hosts.list: no address associated with name
.....

My suggestion was not a skeleton or pseudocode, I expected it to work as-is and you didn't need to modify it to add extra loops. It already had a loop which read servers from your server file one by one and fed them into ssh individually. Did you try my original, unmodified code?

$server_list is a file, therefore, 'for x in $server_list' makes no sense. You read from files.
Code:
server_list='/tmp/hosts.list'

while read SERVER
do
    /usr/local/bin/ssh "$SERVER" printf "${SERVER} : " ';' uptime
done < $server_list

# 13  
Old 03-15-2012
Thanks itkamaraj for the help! I made little changes to the script where the contents of the output.txt are being to my email address. So far everything works perfectly.
Code:
TODAY=`date "+%Y%m%d"`
export TODAY

SERVERS=$(cat /tmp/hosts.list)
for i in $SERVERS;
do 
uptime=$(ssh $i uptime | cut -f1 -d",")
echo "$i $uptime" >> uptimes_${TODAY}.txt
done

cat uptimes_${TODAY}.txt | mailx -s "Uptimes for `date`" myemail@email.com

I am also trying to think of implementing the following.
If i run the script through crontab on Monday morning, i would like the script to print only the servers who have been up for more than one day, this way only the servers that didnt get rebooted will be mailed to my email address. Any thoughts on how i should be handling? Really appreciate all your help so far.
Cheers!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Passing a file name to a variable

Below is the command mv AP_FLEXCUBE_INTERFACE10.txt FTPYMNTE_`date "+%Y%m%d%H%M%S" | tr '' ''`.TXT it is changing the file name to a different name according to time stamp dynamically. I want to capture that dynamic file name present in the directory to a variable . After that i want to... (6 Replies)
Discussion started by: sujit das
6 Replies

2. Shell Programming and Scripting

Help with passing parameters from a file

Hello Everyone, I have developed a shell script which takes schema id and password as parameter to login into database using sqlplus,runs a query and mails the result. My requirement is that, I dont want to pass userid and password as parameters.Instead,I want to pass say Environment... (4 Replies)
Discussion started by: karthik adiga
4 Replies

3. Shell Programming and Scripting

Passing parameter through file

Hi , I am passing date parameter through file my shell script testing.sh is #set -x #set -v asd=$1 asd1=$2 echo $asd echo $asd1 Passing parameter as below sh testing.sh `cat file1.txt` Output (2 Replies)
Discussion started by: kaushik02018
2 Replies

4. UNIX for Dummies Questions & Answers

passing command arguments from a file?

Hi Im trying to run zip shell command from an Oracle job, but this has limitations. This should take a few of explanaition,.. Oracle allows me to execute a command and then I can set up a fixed number of arguments. Ex: (summarizing in something like..): JOB DEFINITION job_name: test... (4 Replies)
Discussion started by: vegatripy
4 Replies

5. Shell Programming and Scripting

Reading a string and passing passing arguments to a while loop

I have an for loop that reads the following file cat param.cfg val1:env1:opt1 val2:env2:opt2 val3:env3:opt3 val4:env4:opt4 . . The for loop extracts the each line of the file so that at any one point, the value of i is val1:env1:opt1 etc... I would like to extract each... (19 Replies)
Discussion started by: goddevil
19 Replies

6. Shell Programming and Scripting

Splitting a file in to multiple files and passing each individual file to a command

I have an input file with contents like: MainFile.dat: 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 ... (4 Replies)
Discussion started by: rkrish
4 Replies

7. UNIX for Dummies Questions & Answers

Passing the parameters through a file

Hi All, I have written a shell script and the script is working fine, I am passing my MIT_ID(NUMBER VALUE) to the shell script from the command prompt and my script is executing as expected. Now I have to pass all the MIT_ID's from a .txt file to the shell script,as I am automating this I... (6 Replies)
Discussion started by: gaur.deepti
6 Replies

8. UNIX for Dummies Questions & Answers

Reading from a file(passing the file as input parameter)

hi I have a shell script say primary.sh . There is a file called params my scenario is primary.sh should read all the values and echo it for example i should pass like $primary.sh params output would be Abc ... (2 Replies)
Discussion started by: ssuresh1999
2 Replies

9. Shell Programming and Scripting

Passing a file descriptor

I am trying to right a function which uses a file descriptor to write to a log file. The problem is that the on the print statement the file descriptor is called bad. Now when I first open the file and print to it in the f_open function by passing the descriptor to f_print_log all works well,... (6 Replies)
Discussion started by: robotball
6 Replies

10. Shell Programming and Scripting

Passing parameters through a file

I have created a script "myscript.sh" I need to run this script with diffrent parameters. The parameters are stored in a file myparam.txt. I need to run myscript.sh script for every parameter supplied in myparam.txt. Example: If myparam.txt contains following lines: param1 param2 param3... (3 Replies)
Discussion started by: chawlaaman
3 Replies
Login or Register to Ask a Question