Grep command is not working when put into cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep command is not working when put into cron
# 1  
Old 08-06-2008
Grep command is not working when put into cron

Hi,

I worte a script which runs perfect when i execute it manually. But when i scheduled into cron the grep command alone is not working.

the sample script,

/usr/bin/grep FTP $subfile > /tmp/tfsrec.dat
tfs=`echo $?`
if [ $tfs = "0" ]
then
echo "FTP FOUND"
else
echo "FTP NOT FOUND"


Where FTP is a string in a set of files which is huge size. Please help me out.
# 2  
Old 08-06-2008
error?

is this your complete script?

could you list the error that you are seeing?
# 3  
Old 08-06-2008
Try something like:

Code:
#!/bin/sh

subfile=.....

# other lines....
# .....

/usr/bin/grep FTP "$subfile" > /tmp/tfsrec.dat
tfs=`echo $?`

case "$tfs" in
  0)    echo "FTP FOUND"
    ;;
  *)    echo "FTP NOT FOUND"
    ;;
esac

Regards
# 4  
Old 08-06-2008
Cron standard output and error output is mailed to your user mailbox. So please check mail command. It is possible to redefine it.
# 5  
Old 08-06-2008
no this is not my complete script. The orginal script is very big. I didnt get any error while putting the script in cron, but the grep condition is not working. For the files which doesnt have the string "FTP" also it displays as FTP FOUND. Not Sure still whats the problem.

Franklin52 thanks for the alterante method. I will try it out and post you the result.

gbielanski let me check the mails and post you.
# 6  
Old 08-06-2008
Do we have any powerfull command other than "grep" ?? Caz, the size of files in which itz looking into is in GB's. It may check nearly to some 100 files for a particular string FTP.

And tat too the word count of the file is zero. Please help me out.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fdisk and grep command not working in udev trigger

Hi Guys, Can someone take a look at my scripts what missing, plugin usb drive the script is running can log all my echo but cannot execute command. Is there any configuration in linux or to my scripts need to add?. What i want to achieve is every time I plugin the usbdisk automatic mount to... (21 Replies)
Discussion started by: lxdorney
21 Replies

2. UNIX for Beginners Questions & Answers

Grep command is not working

I have made a program that reads a text file and checks for palindromic words and then outputs them. They each appear on a new line with a count of the number of occurences beside each of the words. Requirements for being classed as palindrome are that the word must have at least 3 letters and... (7 Replies)
Discussion started by: greenhouse91
7 Replies

3. Linux

Put -r is not working in SFTP

Hi Folks, I am trying to copy a directory along with sub-directories to SFTP server. I have connected to SFTP and tried to run the below command: sftp> get -r abc/* It is throwing the error Invalid flag -r Can you please let me know the ways to copy a directory from Local to SFTP ... (1 Reply)
Discussion started by: kirans.229
1 Replies

4. Shell Programming and Scripting

UNIX command in cron not working

the following unix command gives me the number of records avaiable in my application /navs/sys/appl/bin/record list This gives number of rows and colums. I want to generate one text file everyday at 6:10 AM using cron So I added following entery into crontable #Generate record file at... (6 Replies)
Discussion started by: Nakul_sh
6 Replies

5. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

6. Shell Programming and Scripting

Script is not working from cron while working manually

Hello, I am facing a very strange problem when I run my script manuallu ./Fetchcode which is using to connect with MKS integrity from linux end it workks fine but when I run it from cron it doesn't work.Can someone help me 1) How could I check my script when it is running from cron like... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

7. Solaris

not executable when put in cron

Hi, I have a script that is executed perfectly. When I put it in cron, it is not executed. What could be the reason? thanks (2 Replies)
Discussion started by: melanie_pfefer
2 Replies

8. Shell Programming and Scripting

sudo command is not working inside a script when placed in cron

Hi All, i have a cron entry like 0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /amex/sssmonitor/dss_chk.ksh and the script is like #!/bin/ksh file=`uname -n` > /sunmast/projects/oasis/COREDEV/Dss$file.log > /tmp/output_sss today=`date` varb=`ps -ef | grep... (5 Replies)
Discussion started by: usha rao
5 Replies

9. Shell Programming and Scripting

Sudo command not working with cron job.

Hello, I have written a script that has a sudo command to change file permissions within it. When I run the script manually, the sudo command inside of it works fine. When the script is run through crontab I get the error "cron: not found". It the same user profile that I am using... (6 Replies)
Discussion started by: WhotheWhat
6 Replies

10. Shell Programming and Scripting

Script is not working when put in crontab

Hi there, this is part of my script: /usr/bin/cd /u01/oradata /usr/bin/cp `/bin/ls -1 . |grep -v "^DIMStemp01.dbf$" | grep -v "^DIMSts01.dbf$"|grep -v "^DIMStects01.dbf$"` /backup It's working fine when I manually run on telnet session. /bin/ls -1 . -- to list all the files inside... (2 Replies)
Discussion started by: *Jess*
2 Replies
Login or Register to Ask a Question