LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-12-2014, 12:04 PM   #1
DirtyHowi
Member
 
Registered: Jan 2012
Posts: 34

Rep: Reputation: Disabled
bash issue with sed command not running under cron. could be whole script


i'm trying to get something that runs fine at the command line to run via cron and it don't. which is not unusual.

Code:
  1 #!/bin/bash
  2 cd /data1/mylx08/disk65/WEBSVC-XTRACT/
  3 find . -type f -name '*.err' -mmin +5  | while read filename; do mv -v "${filename}" "`echo "${filename}" | sed -e 's/\.err$/\.deb/'`";done
I'm not sure how to extricate the sed command from the while loop to get it to run the way it should.

all i'm trying to do is replace the .err with .deb if the file is more than 5 minutes old, any other suggestions more than welcome.
 
Old 08-12-2014, 12:09 PM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
set PATH env in script, or use full path

/bin/sed
 
Old 08-12-2014, 12:16 PM   #3
DirtyHowi
Member
 
Registered: Jan 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
tried that, at least its not deleting the files now. thought maybe the echo command was messing up cron since it runs in the background
 
Old 08-12-2014, 12:28 PM   #4
DirtyHowi
Member
 
Registered: Jan 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
all its doing is deleting the file, its not renaming it like it does when run manually
 
Old 08-12-2014, 12:31 PM   #5
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
I would just use find and bash:

Code:
find . -type f -name '*.err' -mmin +5 -exec bash -c 'mv $0 ${0/.err/.deb}' {} \;
Meaning, in your crontab:

Code:
*/5 * * * * find /data1/mylx08/disk65/WEBSVC-XTRACT/ -type f -name '*.err' -mmin +5 -exec bash -c 'mv $0 ${0/.err/.deb}' {} \;
No need for a script to do this.

Last edited by szboardstretcher; 08-12-2014 at 12:36 PM.
 
Old 08-12-2014, 12:49 PM   #6
DirtyHowi
Member
 
Registered: Jan 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
trying now
 
Old 08-12-2014, 12:55 PM   #7
DirtyHowi
Member
 
Registered: Jan 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
@szboardstretcher BRILLIANT. thank you sir.
 
Old 08-12-2014, 02:20 PM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Whenever your script fails to work, use logging to find the bug:

Code:
#!/bin/sh

exec >/tmp/$$.log 2>&1

set -xv

do_some_thing
check <pid>.log files in /tmp
 
Old 08-12-2014, 02:29 PM   #9
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Or use this shebang for bash:

Code:
#!/bin/bash -x
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed command from bash script gushnik1 Linux - Software 6 09-18-2013 02:45 AM
Issue in running shell script using cron job in Unix server. Mundlamuri Programming 7 07-12-2011 11:37 AM
bash script running by cron fakie_flip Programming 17 12-24-2007 10:26 PM
Command interpretation issue in Sed script file angel115 Programming 9 04-21-2006 07:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration