Exiting from the script abruptly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Exiting from the script abruptly
# 1  
Old 11-04-2014
Exiting from the script abruptly

Hi Team,

Need your help for the below code snippet. I wrote a module to read the file names remote server using file name convention.

Issue : My script is coming out from while loop without reading complete file.

HTML Code:
 test1()
{
while read line
do
echo $line
file_nm_convention=`echo $line | awk -F${CFG_DELIMETER} '{print $1}'`
uid=`echo $line | awk -F${CFG_DELIMETER} '{print $2}'`
svr=`echo $line | awk -F${CFG_DELIMETER} '{print $3}'`
dir=`echo $line | awk -F${CFG_DELIMETER} '{print $4}'`
ssh  $uid@$svr "cd $dir;ls -lrt $file_nm_convention"  1>${LST_FILE_NM}
cat $LST_FILE_NM 
done  < ${CFG_FILE}
exit
}
cat cfg_file
test*.ack|kittuad|svr_abc|/home/kittuad
s_test*.ack|kittuad|svr_abc|/home/kittuad

I am getting output only for test*.ack but not for s_test*.ack
# 2  
Old 11-04-2014
How about:
Code:
CF=cfg_file

cat > $CF << EOF
test*.ack|kittuad|svr_abc|/home/kittuad
s_test*.ack|kittuad|svr_abc|/home/kittuad
EOF


oIFS="$IFS"
IFS="|"
while read file user svr home;do
	printf '%s\n' \
		"" \
		"File: $file" \
		"User: $user" \
		"SVR: $svr" \
		"Home: $home"
	ssh $user@$svr << EOF
echo "Tasks on the remote"
cd $home
ls $file
EOF

done<$CF
IFS="$oIFS""

Produces this for me: (added the ssh line later)
Code:
File: test*.ack
User: kittuad
SVR: svr_abc
Home: /home/kittuad

File: s_test*.ack
User: kittuad
SVR: svr_abc
Home: /home/kittuad

Hope this helps

EDIT:
Dont know where LST_FILE_NM is, but its not really required... unless you do another access somewhen later.
But since you just cat the regular ls output, you can loose cat

Last edited by sea; 11-04-2014 at 09:09 PM..
# 3  
Old 11-04-2014
thanks for your reply. I got the solution

made below changes to the code and it is working

Code:
 test1()
{
while read line
do
echo $line
file_nm_convention=`echo $line | awk -F${CFG_DELIMETER} '{print $1}'`
uid=`echo $line | awk -F${CFG_DELIMETER} '{print $2}'`
svr=`echo $line | awk -F${CFG_DELIMETER} '{print $3}'`
dir=`echo $line | awk -F${CFG_DELIMETER} '{print $4}'`
ssh  $uid@$svr "cd $dir;ls -lrt $file_nm_convention"  1>${LST_FILE_NM} </dev/null
cat $LST_FILE_NM 
done  < ${CFG_FILE}
exit
}

# 4  
Old 11-04-2014
Yes ssh was eating your standard input redirect from /dev/null will fix it for you.

It's worth looking at sea's solution as there are some nice techniques for extracting the uid, svr, etc without spawning 3 sub-shells and 3 awks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. SCO

Telnet session disconnects abruptly

I have inherited and SCO OpenServer Release 6 server. The clients connect using telnet to get to a proprietary database application for Service tickets. The issue I am currently having is that the connection just stops abruptly and you can see "telnet session terminated" on the terminal emulation... (22 Replies)
Discussion started by: sean6605
22 Replies

2. Shell Programming and Scripting

Help for exiting the function not script

function2() { cmd1 cmd2 cmd3 .... cmdn } function2() { cmd11 cmd12 cmd13 .... .... } for i in {1,2} (7 Replies)
Discussion started by: yanglei_fage
7 Replies

3. UNIX for Advanced & Expert Users

How to Switch off a Unix machine abruptly

Hi Folks, My UNIX machine is placed geographically in another location. I have a remote access towards it. I want to abruptly switch off my unix machine through remote connection. Is it possible through any UNIX commands? I practically want to power off a PC , something like unplugging a power... (12 Replies)
Discussion started by: gjasper
12 Replies

4. Shell Programming and Scripting

UNIX script abruptly ending due to ssh command

Below UNIX script abruptly ends while reading second line from file. When I comment 'ssh' command the script works as expected. I think I will have to run ssh command in a different process, but haven't got a handle yet as regards to how to do that. Any help in resolving this problem is highly... (1 Reply)
Discussion started by: jeeteshkc
1 Replies

5. Shell Programming and Scripting

Exiting out of the script

I have to write a script in ksh which again should call another script. Say A.ksh is calling B.ksh. Now in B.ksh if the condition we are checking for is true then we have to go back to the main script A.ksh or if the condition in B.ksh is false then we have to totally come out of the scripts. I... (1 Reply)
Discussion started by: vpv0002
1 Replies

6. Shell Programming and Scripting

Bash Script Not Exiting

I have a script planned for the Helpdesk to allow them to (on a couple of RHEL 3 / RHEL 5 servers) reset passwords, stop / start printers, and clear print queues. The appropriate sudo permissions were given to their accounts, and the individual functions all work just fine. The ability to move... (0 Replies)
Discussion started by: tearsong
0 Replies

7. Shell Programming and Scripting

exiting from script

Hi, I am trying to exit the script from a function. I was in assumption that if we use exit ( inside or outside the function) it will exit from the script. alternatively, return will exit from that particular function. but in my case, exit is exiting from the function and not the script.... (8 Replies)
Discussion started by: shellwell
8 Replies

8. Shell Programming and Scripting

shell script exiting before completing

I have a script which has the following statement, /opt/oracle/product/9i/bin/sqlplus << EOC >> $LOG_FILE 2>&1 username/password ---- Enters the SQL prompt @/export/home/oracle/shells/grant_userview.sql ---Runs the SQL script @/export/home/oracle/shells/grant_proc_userview.sql ---Runs the... (6 Replies)
Discussion started by: welldone
6 Replies

9. Shell Programming and Scripting

Exiting a script

I have a script abc.sh. Its contents are as follows: (7 Replies)
Discussion started by: lassimanji
7 Replies

10. Shell Programming and Scripting

exiting from script

there are many script in my project.i am having a problem when i am trying to quit from child script.what is the command to wrap up all the parent script and calling script as well? exit 0 is not working.please help.... (1 Reply)
Discussion started by: arghya_owen
1 Replies
Login or Register to Ask a Question