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:
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?
You might run it more on an expect-like basis, run '(feerer-subshell)|ssh whatevery su -c ksh >logfile 2>&1', feed it commands, check the output for positive indications of success, send more commands. If you redirect output to a local flat file, you can interrogate that file in the feeder subshell to see if it ends in the right stuff.
Hi, I tried the way mentioned above and removed exit command from the script, it still gives comes with exit code 0 and the execution processes further:
Here's the log of above utility:
Info May 9, 2013 10:06:43 PM [stdout: 2] Parsing input file /opt/apps/home/apps/bladelogic_scripts/procedure_name.txt for duplicate values at first column
2
Info May 9, 2013 10:06:44 PM [stdout: 2] ####Error - Duplicate procedure entries exists in the /opt/apps/home/apps/scripts/procedure_name.txt, please remove duplicate values from input file, exiting now.#### avikal is duplicate
2
Info May 9, 2013 10:06:46 PM [stdout: 2] 0
2
Info May 9, 2013 10:06:46 PM [stdout: 2] Export of source procedures complete
2
The OS is solaris, and my used case is to parse the file for duplicate values at column first in export script, if they exists execution should stop completely.
Please advise.
---------- Post updated at 08:59 AM ---------- Previous update was at 04:17 AM ----------
Nevermind guys, sleep before catching the exception was the issue. Script is now working as expected. Apologies and thanks for the inputs.
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)