Sponsored Content
Top Forums Shell Programming and Scripting Catching exception of commands executed under ssh and su Post 302804421 by avikaljain on Wednesday 8th of May 2013 02:33:18 PM
Old 05-08-2013
Catching exception of commands executed under ssh and su

Hello experts,

I have one wrapper script which runs on server104, the purpose of the script is to ssh on server109; perform su to application user; and execute exports script.

I want wrapper script to stop executing further if my exports script comes out with exit 1. My current setup keeps on running even if the export script fails at some point, I believe this is because I am running it under ssh command since it returns exit 0 to my current shell.

Script looks like this:

Code:
ssh -i /opt/apps/lib/keys/nfs_appsadm_key $apps_USER@$SOURCE_MACHINE_NAME <<EOT 

echo $SOURCE_SW_NAME 
sudo su - $SOURCE_SW_USER <<EOT 
  
        /opt/apps/home/apps/bladelogic_scripts/export.sh -t $TICKET_NUMBER -f $LIST_FILE 
                        
exit 
EOT 
echo Export of source apps complete  | tee  -a $BATCH_PROMO_LOG 
  
echo "####Copying the exported content from $EXP_DIR on $SOURCE_MACHINE_NAME to $IMP_DIR on localhost.####" 

scp -i /opt/apps/lib/keys/nfs_appsadm_key -r $apps_USER@${SOURCE_MACHINE_NAME}:${EXP_XFR_DIR}/*.* $IMP_DIR 
echo "Changing permission of recently modified files in $IMP_DIR" 
cd $IMP_DIR 
find . -type f -mtime -1 -exec chmod 777 {} \; 
#chmod -R 777 $IMP_DIR/*.txt
#chmod -R 777 $IMP_DIR/"$TICKET_NUMBER"_detail.txt

I can write the exit code of exports script in a temp file and then scp it to server109, check its existence and code wrapper to come out if it exists but feel I am complicating it, any easy solutions to catch the exception and stop execution of wrapper if exports script throws error?

Any feedback is appreciated.

Thank You.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Capturing commands executed by user

Hello Unix Champs, For keeping audit trail, I want to log the commands entered by the normal users, on their terminal into a text file. I tried putting a "script -a username.timestamp.txt" in the user profile file, but script command stops execution when user types exit or presses CTRL+D... (3 Replies)
Discussion started by: bhaven.haria
3 Replies

2. Solaris

I want to know whole day commands executed by particular user

Hi all I want to know the commands executed a by particular user .. for the whole day on my machine. I have checked out with the commad $lastcomm <user> It is throwing an error called: .. /var/adm/pacct: No such file or directory Can u help me in this regard.. Thank U... (3 Replies)
Discussion started by: naree
3 Replies

3. Solaris

whole day commands executed by particular user

Hi all I want to know the commands executed a by particular user .. for the whole day on my machine. I have checked out with the commad $lastcomm <user> It is throwing an error called: .. /var/adm/pacct: No such file or directory Can u help me in this regard.. Thank U Naree (1 Reply)
Discussion started by: naree
1 Replies

4. UNIX for Dummies Questions & Answers

How does the internal commands are executed?

Hi all, I am new to unix OS. Commands(external commands) given by the user are examined by shell and later executed by kernel. Now I want to know how the internal(built in) commands are executed. Please clarify whether they are executed directly by shell or by kernel. Thanks in... (2 Replies)
Discussion started by: chaitra
2 Replies

5. Shell Programming and Scripting

Viewing the commands executed

Hi, I have executed a set of commands on the linux server and later rebooted the server. Is it possible to get the details of the commands I executed prior to the reboot? If yes please let me know how? Thanks. (1 Reply)
Discussion started by: yoursdavinder
1 Replies

6. Shell Programming and Scripting

To inform the executed commands

Dear friends, Whenever I do logout from a session initiated by ssh/su, I need to print a small report which says the login time, logout time, commands got executed.. How can it be done? I know when doing ssh, .profile file will get executed. Shall we do something with the help of it. (1 Reply)
Discussion started by: nagalenoj
1 Replies

7. UNIX for Dummies Questions & Answers

Clearing history of commands executed

Hi, I have cleared the commands by using >$HOME/.sh_history. But if i issue HISTORY it shows some reference numbers but not the commands executed. But i want to truncate those line numbers too. May i know how i can achieve this? Thanks (1 Reply)
Discussion started by: pandeesh
1 Replies

8. Shell Programming and Scripting

Catching the exception in multiple logs

Hi folks, I have logs folder in which different type of logs are generated , I am monitoring them by the below command tail -f *.log but I want that if exception come in any of the logs then it should be catch so what i should prefix with tail -f *.log so that it imeediatley catches and... (3 Replies)
Discussion started by: punpun66
3 Replies

9. Shell Programming and Scripting

How to time stamp executed commands?

Hi guys, I am executing a pretty long ksh script and need to time stamp every command which runs inside. Unfortunatly 'echo date' is not the option here. May be someone knows another way or utility which can be used to log executed command and timestamp next to it. Thanks PS I work in ksh88 (4 Replies)
Discussion started by: aoussenko
4 Replies

10. UNIX for Dummies Questions & Answers

List commands executed on a server

Hi All, how to list all the commands executed by users on a linux server.... I dont have access to others .bash_history. and i am not root user.. Please help.. Thanks in advance.. (6 Replies)
Discussion started by: nanz143
6 Replies
SSH-ARGV0(1)						    BSD General Commands Manual 					      SSH-ARGV0(1)

NAME
ssh-argv0 -- replaces the old ssh command-name as hostname handling SYNOPSIS
hostname | user@hostname [-l login_name] [command] hostname | user@hostname [-afgknqstvxACNTX1246] [-b bind_address] [-c cipher_spec] [-e escape_char] [-i identity_file] [-l login_name] [-m mac_spec] [-o option] [-p port] [-F configfile] [-L port:host:hostport] [-R port:host:hostport] [-D port] [command] DESCRIPTION
ssh-argv0 replaces the old ssh command-name as hostname handling. If you link to this script with a hostname then executing the link is equivalent to having executed ssh with that hostname as an argument. All other arguments are passed to ssh and will be processed normally. OPTIONS
See ssh(1). FILES
See ssh(1). AUTHORS
OpenSSH is a derivative of the original and free ssh 1.2.12 release by Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo de Raadt and Dug Song removed many bugs, re-added newer features and created OpenSSH. Markus Friedl contributed the support for SSH protocol versions 1.5 and 2.0. Jonathan Amery wrote this ssh-argv0 script and the associated documentation. SEE ALSO
ssh(1) Debian Project September 7, 2001 Debian Project
All times are GMT -4. The time now is 07:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy