Exits from putty instead of shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Exits from putty instead of shell script
# 1  
Old 02-04-2011
Exits from putty instead of shell script

Dear,

I have written below code to initiate the log at top of my script.
Code:
#Set the log file
LOGFILE=<path>/<filename.log>
exec > $LOGFILE 2>&1
...............
....
...
..
............
echo -e  "\n\n Script finished OK " `date "+%m/%d/%y %H:%M:%S" ` "\n\n"
exit 0

the logging ends only after giving 'exit 0' in the bottom, but this 'exit 0' also terminates and closes the unix session, but my need is to have the control in next command prompt.

Pls advice.

Last edited by Franklin52; 02-04-2011 at 03:17 AM.. Reason: Please use code tags
# 2  
Old 02-04-2011
I believe this happens when you source the script.

if you run:
Code:
. /path/to/my/script

It will close the session.

If you run:
Code:
/path/to/my/script

It should work.

Notice the 'dot''space' in the first example. Let us know if this is the case.

Now, if this is a subscript, being called from a master script, simply take the exit out.
# 3  
Old 02-04-2011
Quote:
exec > $LOGFILE 2>&1
Doesn't "exec" start a new Shell?
Anyway, what output do you want to go into $LOGFILE ? There should be an alternative technique without using "exec".


What Operating System and Shell is this:
Code:
uname -a
echo $SHELL

# 4  
Old 02-07-2011
Dear thx for ur reply.

exec does not start a new shell, but if i dont give exit 0 at the bottom it hangs (logs including the new promt)

Code:
$ uname -a
Linux jasmine 2.6.16.60-0.54.5-smp #1 SMP Fri Sep 4 01:28:03 UTC 2009 x86_64 x86_64 x86_64 GNU/Linux
$ echo $SHELL
/bin/bash

Yes i run using dot & space. it is individual program(but no problem when run via master program bcos master pgm run diff machine), i am just logging echo stuffs and other for debugging purpose.

Thanks
Imran
# 5  
Old 02-07-2011
If you still need help, post all the programs you are using and how you are running them.
# 6  
Old 02-07-2011
Quote:
Originally Posted by Imran_Chennai
...
Code:
$ uname -a
Linux jasmine 2.6.16.60-0.54.5-smp #1 SMP Fri Sep 4 01:28:03 UTC 2009 x86_64 x86_64 x86_64 GNU/Linux
$ echo $SHELL
/bin/bash

Yes i run using dot & space. it is individual program(but no problem when run via master program bcos master pgm run diff machine), i am just logging echo stuffs and other for debugging purpose.
...
Try using "return" with dot notation -

Code:
$
$
$ cat -n f8.sh
     1  #!/usr/bin/bash
     2  echo "Hello, World!"
     3  return 1
$
$ # The following prints "Hello, World!", and returns control to the
$ # shell prompt with exit status 1
$
$ . f8.sh
Hello, World!
$
$ echo $?
1
$
$

tyler_durden
# 7  
Old 02-08-2011
Hi,

The 'return' also leads to hang, and but log is ok including 4 prompt lines at the end.

Is there any alternate way to establish log without exec & exit.

I am using this logic for 4 inividual scripts (bash) that runs daily, two of them are for sqlldr and others calling SP., I have to login putty 4 time to accomplish this.

Thanks
Imran
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash script to compare file all the files exits or not

Currently i am building a script like based on region parameter it will filter the records in config file and then it will create a text file like ab.txt and it will read the path location in that file and now i need to compare the files name in the config file to files in the path of the config... (1 Reply)
Discussion started by: saranath
1 Replies

2. UNIX for Beginners Questions & Answers

Script to check if files exits

Hi In live system core files are generating frequently. around 10 core files in 30 mins in root file system. which is eating my space very much below is core file core.56539 core.78886 core.12302 core.80554 core.20147 I am trying to write a script which should move... (7 Replies)
Discussion started by: scriptor
7 Replies

3. Shell Programming and Scripting

Script exits when using UNIX2dos / dos2UNIX

I'm not sure why but my script quits automatically at the point where unix2dos / dos2unix command is used. :confused::confused::confused: How do a fix it? LOG_FILE=MADDY.txt unix2dos ${LOG_FILE} exec 2> $LOG_FILE 1>&2 echo ${LOG_FILE} The script exists after the below... (3 Replies)
Discussion started by: machomaddy
3 Replies

4. Windows & DOS: Issues & Discussions

Method to run a shell script using shortcut key in keyboard with out logging to putty

Dear All, I want to run a shell script with out logging to putty but configuring it to a keyboard short cut it windows PC. Can this be done? I want this to rename a log in a specified folder in a system Thanks (8 Replies)
Discussion started by: Chi_SL
8 Replies

5. UNIX for Dummies Questions & Answers

Script dosent exits after executing the script

Hi i wrote a script which dosent exists after executing any help #!/bin/bash netstat -ptlen | grep 10000 if ; then echo "Hive Thrift server is running" exit 0 else echo "Hive Thrift server is down Trying to Bring up the service" | mail -s "ALERT" team@domain.com `nohup hive... (7 Replies)
Discussion started by: vikatakavi
7 Replies

6. Shell Programming and Scripting

ksh: hash (#) at beginning of a line exits the shell

This is WILD! :eek: Under Ubuntu (where I am cross-posting this problem) I have lately noticed by terminal windows/tabs closing unexpectedly. I finally caught it: I was composing a complicated command so I practices it a few times commented out - that is, with a # at the start of the line. What... (3 Replies)
Discussion started by: rpaskudniak
3 Replies

7. Shell Programming and Scripting

Shell scripts exits after executing ypmatch

Hello - I have a script which creates a NIS user on Solaris machine. Before creating the user I check if the user being created laready exists or not using ypmatch and use $? to get the exit code. If a user exists, I get 0, works fine. However when the user is not found, the shell scripts exits by... (1 Reply)
Discussion started by: manju--
1 Replies

8. Shell Programming and Scripting

'script' command exits immediately

I'm trying to capture the output of some commands with the 'script' utility. Normally, I would type 'script /path/to/output/file', then enter commands, then hit ctrl+D to end the 'script' capture. I'm having trouble with it on a server. Upon starting 'script', it exits immediately before I type... (6 Replies)
Discussion started by: jalburger
6 Replies

9. Shell Programming and Scripting

Renaming putty windows with a shell script

i frequently have to open multiple putty windows to ssh into a unix server running HP-UX 11.23. Since i use some of the windows for dedicated processes i would like to rename them (the caption displayed in the titlebar) to something more convenient than the standard <Host>.<Server>.com While... (4 Replies)
Discussion started by: orno
4 Replies

10. Shell Programming and Scripting

Script exits with $? not 0 randomly, how can I see what command failed?

Hi! I have this situation with 3 shellscripts. One is a "startscript" that simply calls other scripts. This one is scheduled with cron to run at regular intervals. That script runs what I'll refer to as Script 1. Script 1 in turn runs script 2 (import_catalogs_buyer.sh) Sometimes, seemingly... (2 Replies)
Discussion started by: trailsmoke
2 Replies
Login or Register to Ask a Question