ssh script for connecting unix system.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh script for connecting unix system.
# 1  
Old 07-15-2008
ssh script for connecting unix system.

Hi All,

I've a log file call netbackup.log in all the 5 servers in location usr/netbackup.log. I dont want to login in each server and check the log file. So i wanted to have a script written to have the log information at one place.

I want to have the last 2 lines from the file netbackup.log from all the servers and write in a new log file using ssh and send a mail.

Can anyone plz help me out how to write a script which connects a another unix system and get the last 2 lines of a particular log file.

Thanks in advance.
Suri tyson
# 2  
Old 07-15-2008
1. Enter this "ssh without password" in your favourite internet search engine and set it up accordingly between your collecting server and all the other servers you gonna ask for the Netbackup logs.
2. Write a script that could look like this:
Code:
RESULTFILE=/myoutfile
HOSTLIST="hosta hostb hostc hostd"

if [[ -e ${RESULTFILE} ]]; then
   rm -f ${RESULTFILE}
fi

for HOSTR in ${HOSTLIST}; do
   echo ${HOSTR} >> ${RESULTFILE}
   ssh -o "batchmode" myuser@${HOSTR} "tail -2 /where/is/my/netbackup.log" >> ${RESULTFILE}
   if (( $? != 0 )); then
      echo "Something went wrong with ssh to Host ${HOSTR}, check the logs!"
   fi
done

(echo "Here comes the mail again.."; uuencode ${RESULTFILE} ${RESULTFILE}) | mail -s "Some subject" myaddress@somedomain.org

exit 0

# 3  
Old 07-28-2008
Hi Zaxxon, thanks it worked;however would like to know one more thing...

I've made it possible by using two scripts.

1.)test_ssh1.sh

#!/bin/ksh
RESULTFILE=/oracle/PC9/netbackup.log
if [[ -e ${RESULTFILE} ]]; then
rm -f ${RESULTFILE}
fi


/usr/sap/sapshare/scripts/test_ssh2.sh Q03 sf2dom1

/usr/sap/sapshare/scripts/test_ssh2.sh D01 sol5500

/usr/sap/sapshare/scripts/test_ssh2.sh D02 jdcss039




2.)test_ssh2.sh


#!/bin/ksh

##############################################################################################
export ORACLE_SID=$1
export primaryhost=$2
export sid=`echo $ORACLE_SID| tr ['A-Z'] ['a-z']`
##############################################################################################

RESULTFILE=/oracle/PC9/netbackup.log

#############################################################################################
## Step 1 - Get the last created backup log
#############################################################################################
ssh -l ora${sid} ${primaryhost} "tail -2 /oracle/$ORACLE_SID/newbackup/sap_netbackup.log" >> ${RESULTFILE}

exit 0

And then it sends the mail.. looks like this

Oracle Q03 End Hot BACKUP Time: 07/23/08 14:18:15
Oracle Q03 Begin Hot BACKUP Time: 07/24/08 18:35:46
Oracle D01 Begin Hot BACKUP Time: 07/11/08 21:00:48
Oracle D01 End Hot BACKUP Time: 07/12/08 17:28:24
Oracle D02 Begin Hot BACKUP Time: 07/23/08 21:01:23
Oracle D02 End Hot BACKUP Time: 07/24/08 01:32:32

However i want to read the last line of the log file with name End Hot BACKUP and calculate the time taken from Begin Hot BACKUP to End Hot BACKUP and display the difference in hours/minutes.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Connecting to Windows server from UNIX through script

I am trying to connect to a Windows server say 10.1.1.10. This servers has a folder named RAJ in which there are multiple .zip files. All these zip files contain a text file called XYZ.txt. Now i have to merge the content of these XYZ.txt files from each of the .zip file and create a new text... (1 Reply)
Discussion started by: swapniljadav
1 Replies

2. UNIX for Advanced & Expert Users

Connecting using ssh

We have 2 different servers say A and B and I want to check the log file of 2 servers simultaneously. If I am logged into server A how can I connect to server B. I have used ssh username@B.But it is asking password. How can I give the password on ssh. Or is there any other utility for... (2 Replies)
Discussion started by: jim john
2 Replies

3. Shell Programming and Scripting

connecting to table to extract multiple rows into file from unix script

I need to extract the data from oracle table and written the below code. But it is not working.There is some problem with the query and output is shown is No rows selected" . If I run the same query from sql developer there is my required output. And if I run the shell script with simple sql... (7 Replies)
Discussion started by: giridhar276
7 Replies

4. Linux

connecting to SSH

Well im on Fedora, and theres no sub section for Fedora so yea Well how do you connect to an SSH, while on a windows terminal? And also to transfer a file from my desktop to a server? how is this done scp command is not working for me (3 Replies)
Discussion started by: gangsta
3 Replies

5. UNIX for Advanced & Expert Users

Unix FTP Script connecting through proxy Not working

Hi All, can some one please help me to solve this issue, its urgent:confused: We need to FTP a file form our Unix server to an external client FTP location. I am trying to connect to the proxy server first and then use the below USER comment to connect to the external FTP server, and its working... (3 Replies)
Discussion started by: JesusJoseph
3 Replies

6. Shell Programming and Scripting

Connecting to multiple unix server from unix server using shell script

Hi Gurus, I'm a unix newbie and I would like to connect to multiple unix servers from unix server using shell script i.e from server a to server b,c,d etc. I want to copy the files from unix server a to server b, c, d. I can access staright using ssh without the need to have password and user... (5 Replies)
Discussion started by: sexyTrojan
5 Replies

7. Shell Programming and Scripting

Executing a script on a remote system via SSH

Hello all, I have a relatively simple script I wrote to generate a count of errors broken down. What I would like to do is execute this script from another server so that I don't actually have to log in to the server to run the check. The script on what we'll call "Server A" is: ... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

8. Shell Programming and Scripting

Connecting and Querying DB2 database from Unix Script?

I am trying to develop a script that can connect to a DB2 database mainframe and Query the database and display the results. I've been researching, but I have yet to find a definitive solution where I can enter in the Mainframe DB2 address db2:// and query the database and return the results. If... (2 Replies)
Discussion started by: developncode
2 Replies

9. UNIX for Advanced & Expert Users

connecting windows remotely from unix using SSH

Hi Can someone giv me some knowledge on accesing windows from unix and executing DOS scripts using SSH I would like to know how to go abt it...am new to it. Thanks in advance (1 Reply)
Discussion started by: lakshmis10
1 Replies

10. Shell Programming and Scripting

connecting to remote db from unix script

Hi everybody, My bash script is trying to connect to a remote database using the 'sqlplus' binary.For this i set(export) the variable TWO_TASK to the value of database name excluding the dot extension part. Can anyone explain me what's the significance of this TWO_TASK variable while... (8 Replies)
Discussion started by: DILEEP410
8 Replies
Login or Register to Ask a Question