Script working successfully only when executed twice


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Script working successfully only when executed twice
# 1  
Old 04-29-2010
Script working successfully only when executed twice

Guys,

i am facing a very strange issue, my code below does an ftp to server A and gets a file to Server B, once the file is in B an if condition is present to check if the pattern of the filename is ABC* then it has to be encrypted using OPENSSL as ABC.enc else if it of pattern 123* has to be encrypted in a different way.

My issue is that the script has to be executed twice to get the expected result. The First execution itself does not perform the encryption. This occurs for files of large and small size.

Code:
./getfile_encrypt.ksh;
 
ABCCount=`ls -lrt ABC* | awk '{print ($9)}' | wc -l`;
 
echo "FTP IS DONE"
 
if [[ ${ABCCount} -gt 0 ]] then
 
     echo "BEFORE OPENSSL"
     OPENSSL......
     echo "AFTER OPENSSL"
fi

the getfile_encrypt.ksh just performs an FTP and gets the file.

when i execute the script, i get the following

Code:
 
FIRST TIME
 $ ./encrypt_ABC.ksh
 ls: 0653-341 The file ABC* does not exist.
 THE FTP IS DONE
 
SECOND TIME
 $ ./encrypt_ABC.ksh
  THE FTP IS DONE
 JUST BEFORE OPENSSL
 JUST AFTER OPENSSL

Please let me know why the script is exiting half way the first time and the second time it is executed, it runs successfully eventhough i do not make any change. eventhough it says ABC* does not exist the first time, it is present in the local path of the server B.
# 2  
Old 04-29-2010
Quote:
Originally Posted by meva
eventhough it says ABC* does not exist the first time, it is present in the local path of the server B.
It isn't present yet otherwise it wouldn't say ABC* doesn't exist.
# 3  
Old 05-04-2010
Change the "ls -lrt" to "ls -1rt" and get rid of the awk command.
You should also redirect stderr from the ls to /dev/null.

Last edited by vinbob; 05-04-2010 at 09:27 PM..
# 4  
Old 05-05-2010
you must start the script when FTP proccessing completely succesfully finished
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check if the JAVA Program is successfully executed in sh shell scripting

Hi , I have written a shell script to call a java program say load_id.sh .This sh script indeed is executed implicitly in other sh script which calls 2 more sh scripts one by one. I need to check if the load_id.sh (which calls java program) is executed successfully only then continue with... (1 Reply)
Discussion started by: preema
1 Replies

2. Shell Programming and Scripting

Linux/bash Script only working if executed from shell prompt

Hi, maybe I'm asking a VERY dumb question, but would anybody out there tell me, why this f****** script won't work if executed as a cronjob, but works fine if executed from a shell prompt? #! /bin/bash set PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin date >>... (3 Replies)
Discussion started by: beislhur
3 Replies

3. Shell Programming and Scripting

Need to echo command successful if command is executed successfully

Hello, I have written a command n shell script : srvctl relocate service -d t1 -s s1 -i i1 -t t1 -f If the above command executes successfully without error I need to echo "Service relocated successfully and If it errors out I need to trap the errors in a file and also need to make... (1 Reply)
Discussion started by: Vishal_dba
1 Replies

4. Shell Programming and Scripting

Did my script execute successfully ?

Hi, I have two scripts viz and I am running them in background. I wish to know if both the scripts completed execution successfully. So this is what I have done /tmp/commet/bin/connectdb1.sh & condb1=$? /tmp/commet/bin/connectdb2.sh & condb2=$? However, I am getting error... (7 Replies)
Discussion started by: mohtashims
7 Replies

5. Shell Programming and Scripting

script has been executed successfully or not??

Guys, How can we know whether a script has been executed successfully or not ? We dont have any log directories, and we are not given a chance to modify the script. Could someone help me out with this Thanks (2 Replies)
Discussion started by: bobby1015
2 Replies

6. AIX

Script not getting executed via cron but executes when executed manually.

Hi Script not getting executed via cron but executes successfully when executed manually. Please assist cbspsap01(appuser) /app/scripts > cat restart.sh #!/bin/ksh cd /app/bin date >>logfile.out echo "Restart has been started....." >>logfile.out date >>logfile.out initfnsw -y restart... (3 Replies)
Discussion started by: samsungsamsung
3 Replies

7. Shell Programming and Scripting

System Command dies even when command gets executed successfully

Hi I have created a perl script & running it using Linux machine. I want my script to die when system command is unsuccessful but script is dying even when system command gets executed successfully. :wall: I am using the command below :- system($cmd) || die "FAILED $!"; print "Hello"; ... (2 Replies)
Discussion started by: Priyanka Gupta
2 Replies

8. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

9. UNIX for Advanced & Expert Users

commands not working if the executed from forked process

Hi, I have an application where if it runs indivisually could able to execute commands (like system("ls")) and could able to execute tcl script. Same application if started from health monitor process (From health monitor process my application will be forked), it could not execute the... (1 Reply)
Discussion started by: chandrutiptur
1 Replies
Login or Register to Ask a Question