One Line for loop in CRON


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers One Line for loop in CRON
# 1  
Old 01-06-2012
One Line for loop in CRON

Hello,

I'm trying to run a one line for loop from the CRON. This is the exact command
Code:
 /bin/bash for file in $(/bin/find /opt/local/edw_extract/logs -name "*.log"); do /bin/cat /dev/null > $file; done

This will run from the command successfully.



When I schedule this to run it will error out and produce the following output


Code:
/bin/bash for file in $(/bin/find /opt/local/edw_extract/logs -name "*.log"); do /bin/cat /dev/null > $file; done

produced the following output:

sh: syntax error at line 1: `(' unexpected


Could someone explain the proper way to do this?
Is this even possible?


Thank You.


mhauff

Last edited by jim mcnamara; 01-06-2012 at 05:41 PM.. Reason: please use code tags
# 2  
Old 01-06-2012
Try this:
Code:
/bin/bash -c 'for file in $(/bin/find /opt/local/edw_extract/logs -name "*.log"); do > $file;  done'

See if that helps. Generally, complex commands in cron cause way more trouble than just writing a simple shell script that you invoke from cron. And you save nothing worth worrying about in performance
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 01-06-2012
I'd check the environment variables. it seems they need to be specified for cron
# 4  
Old 01-06-2012
Thanks

Thanks to everyone for the quick responses. Jim's response worked. Thank you.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting an unexpected newline in my while loop line-by-line feed

Hi, I'm trying to get a line returned as is from the below input.csv file in Bash in Linux, and somehow I get an unexpected newline in the middle of my input. Here's a sample line in input.csv $> more input.csv TEST_SYSTEM,DUMMY@GMAIL.COM|JULIA H|BROWN And here's a very basic while loop... (7 Replies)
Discussion started by: ChicagoBlues
7 Replies

2. Shell Programming and Scripting

Issue in running a command line utility in CRON

Hi Everyone! I am facing an issue in running a command line utility from the CRON. This utility displays IPC statistics on UNIX message queues: The "queue name" and the "count" of messages in the queue. When running this utility from prompt, it will provide an output on the screen, like the... (4 Replies)
Discussion started by: vai_sh
4 Replies

3. Shell Programming and Scripting

Reading line by line from live log file using while loop and considering only those lines start from

Hi, I want to read a live log file line by line and considering those line which start from time stamp; Below code I am using, which read line but throws an exception when comparing line that does not contain error code tail -F /logs/COMMON-ERROR.log | while read myline; do... (2 Replies)
Discussion started by: ketanraut
2 Replies

4. Shell Programming and Scripting

cron woes - line too long ??

Here is my cron entry: 13 10 * * * /home/my_login/mystf/myscriptsize.sh > /home/my_login/mystf/`date +"%Y%m%d"`log.csv Here is my cron error: unexpected EOF while looking for matching ``' ...cron executes: /home/my_login/mystf/myscriptsize.sh > /home/my_login/mystf/`date +" ..and NOT... (2 Replies)
Discussion started by: landog
2 Replies

5. Shell Programming and Scripting

s3cmd works on command line not on cron

Ubuntu 9.10 is my linux distro Based on forums they say that the problem is with environment . here is my case: login as user, then sudo -s using this command: s3cmd put file s3://bucket >>worked! now here is the simple script intended for testing: #! /bin/bash env >/tmp/cronjob.log... (1 Reply)
Discussion started by: qwerty20
1 Replies

6. Shell Programming and Scripting

[PHP] endless loop mimics a cron. Make sure only one instance is running

Hi, PHP user here. I'm using an endless loop to perform to mimic a cron. The script does something every 20 minutes. It sleep()s in the meantime. I have various checks that ensure that only instance can run, including a "gentleman agreement" locked file. However, I'd like to make sure... (2 Replies)
Discussion started by: jjshell
2 Replies

7. Shell Programming and Scripting

Please let me know what this line in cron means?

Hi All, I found this line in my crontab.. 0 6 * * * "some script name" my question is it means the script should run at 6 00 am. But on what those days are not mentioned. Then in that case when will the script will run? Thanks for ur help in advance, Magesh (3 Replies)
Discussion started by: mac4rfree
3 Replies

8. UNIX for Dummies Questions & Answers

Script through cron and command line

I have a script which runs fine through command line, but doesn't run through cron. There are some variables which are set by the .profile file which are used by the script. Is it that cront does not pick these variables. $/export/home/rahul/bin/createfile.sh >>... (3 Replies)
Discussion started by: rahulrathod
3 Replies

9. UNIX for Advanced & Expert Users

process nice level command line vs cron

Under, Solaris 10 I have the following problem: A script executed at command line runs with nice level 0, as expected. Same script started under (user) crontab runs with nice level 2. I would prefer it run at 0. Is this possible? If so, how? Thanks. (0 Replies)
Discussion started by: henrydark
0 Replies

10. UNIX for Dummies Questions & Answers

One line of cron is not working - PLS Help

Hi all, I have spent 2 hours going through the forum and have not found an answer to my question, I hope someone can help. I have cron setup to run two commands, one at 1am and one at 3 am, the one at 1 am works but not the one at 3 am. The time is set as: 0 1 * * * /path/to/file 0 3 * * *... (3 Replies)
Discussion started by: burnie
3 Replies
Login or Register to Ask a Question