Sponsored Content
Top Forums Shell Programming and Scripting Script in bash that works only some of the time Post 302960920 by Don Cragun on Sunday 22nd of November 2015 02:19:37 AM
Old 11-22-2015
And even if grep of a directory made sense, the commands at the end of the pipeline:
Code:
grep -c filename.$DATE.TXT | grep TRL | wc -l

will always return 0; never 1. The grep -c output will always be a numeric string (that cannot contain the string TRL) and wc -l reading from an empty pipe will always return 0.

Therefore, this loop in your code:
Code:
#this bit waits for the file to finish generating
while [ $mytest15 -ne 1 ]
do
mytest15=`cat /pathtofile/ | grep -c filename.$DATE.TXT | grep TRL | wc -l`
sleep 180
done

cannot ever complete. It is an infinite loop unless the while loop is failing with a syntax error because $mytest expands to an empty string the first time through the loop yielding a syntax error on:
Code:
[ -ne 1 ]

but, since you said it is working successfully when you run it in the foreground, there obviously were not any diagnostic messages printed. So, we have to assume that part of the code you chose not to show us predefined mytest to have the value 1 before the above loop was executed.

If you want to know whether or not a file contains the string TRL, you would not do that with:
Code:
mytest15=`cat /pathtofile/filename | grep -c filename.$DATE.TXT | grep TRL | wc -l`

either. You might want to try a simpler loop like:
Code:
#this bit waits for the file to finish generating
while ! grep -q TRL /pathtofile/filename
do	sleep 180
done

This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Works from bash prompt, but not from script!

I'm trying to use unison from bash on windows with cygwin. I don't know if this is a cygwin question, bash question or unison question. Since I always get reprimanded by the cygwin mailing list for assuming it is a cygwin problem, I'll assume it is a bash question. The following commands work... (7 Replies)
Discussion started by: siegfried
7 Replies

2. Shell Programming and Scripting

Script works with bash 3.0 but not 3.2.

Hello, So my knowledge of bash scripting is not that great and I have been trying to solve this problem on my own for awhile to no avail. Here's the error I get when running it with an OS that uses bash 3.2.x: testagain.sh: line 10: *-1: syntax error: operand expected (error token is... (2 Replies)
Discussion started by: forkandspoon
2 Replies

3. Shell Programming and Scripting

bash script to count the time of transaction

Halo, Bash Script can get the time of process the trasaction or not? For example, bash script use to procee the trasaction, like select and checking.. then generate the XML. after it, i need to get the time which to count the process. Anyone can help me? Thank you (1 Reply)
Discussion started by: ryanW
1 Replies

4. Shell Programming and Scripting

How to compare time in bash script?

Hi, Anyone know how to compare the time in bash script? I want to compare say 30 min. to 45 min. ( AIX ) Thanks. (1 Reply)
Discussion started by: sumit30
1 Replies

5. Shell Programming and Scripting

Ftp script hangs for first time,but works every second time

Hi I have an ftp script which works fine when i execute through a test scheduler(UC4), but when i run it through the prod scheduler(UC4), it hungs indefinetely, when we cancel the job and re-run it it works perfectly fine. here is the code,, any idea why this is happening ???? ... (1 Reply)
Discussion started by: selvankj
1 Replies

6. Shell Programming and Scripting

Need bash script to ping the servers and rename the output file each time the script is ran

HI, I have a file serverlist in that all host names are placed. i have written a small script #./testping #! /bin/bash for i in `cat serverlist` do ping $i >> output.txt done so now it creates a file output.txt till here fine.. now each time i run this script the output file... (4 Replies)
Discussion started by: madhudeva
4 Replies

7. UNIX for Dummies Questions & Answers

Bash script dont works when executed as cronjob

Hello, i have cronjob: crontab -l * * * * * pkill -f domexpcheck;sh /root/dom/domexpcheck.sh it runs: /var/log/cron Mar 25 12:11:01 vps crond: (root) CMD (pkill -f domexpcheck;sh /root/dom/domexpcheck.sh) but somehow script dont run properly via cronjob. But when i execute cronjob... (7 Replies)
Discussion started by: postcd
7 Replies

8. Shell Programming and Scripting

Bash Script Looping all the time

Hello, I have a database file, named data.txt, and a shell script (convert.sh) to convert data.txt from columns to row. Output file name will be column_to_row.txt In this example data.txt has only four rows. Format of data.txt is: info name surname telefon_nr Data.txt info boris... (1 Reply)
Discussion started by: baris35
1 Replies

9. Shell Programming and Scripting

Calling bash script works when called manually but not via Cron?

Hi, I've got a Bash backup script I'm trying to run on a directory via a cron job nightly. If I ssh in and run the script manually it works flawlessly. If I set up the cron to run evertything is totally messed up I don't even know where to begin. Basically the path structure is ... (6 Replies)
Discussion started by: wyclef
6 Replies

10. UNIX for Beginners Questions & Answers

Command works interactively but not in bash script

The below command works in the terminal interactively but not as part of a bash script. I though maybe I needed to escape the "$dir" so it isn't interpreted literally, but that's not it. Thank you :). interactively in terminal dir=/path/to new=$(ls "$dir"/*.csv -tr | tail -n 1) && echo... (6 Replies)
Discussion started by: cmccabe
6 Replies
All times are GMT -4. The time now is 02:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy