LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-08-2010, 02:41 AM   #1
CCH
LQ Newbie
 
Registered: Oct 2010
Posts: 7

Rep: Reputation: 0
Create a crontab that renames a file?


Hello,

I've tried to create a crontab that renames a fil extension every minute. This is what I've tried:

*/1 * * * * / rename /home/bodil/Avräkningsfiler/'s/\.txt/dat/' *.txt

But it doesn't seem to work.

I've also tried to create a .sh file in the catalog itself with the command executing directly in the catalog but even though running the command by typing it in, it doesn't run automatically by cron.

Thanks for your help!
 
Old 10-08-2010, 02:44 AM   #2
prayag_pjs
Senior Member
 
Registered: Feb 2008
Location: Pune - India
Distribution: Fedora,RedHat,CentOS,Gentoo
Posts: 1,145
Blog Entries: 4

Rep: Reputation: 147Reputation: 147
Create a script that renames a file and put it in crontab to run every minute.
Also try giving absolute path of commands used in crontab
 
Old 10-08-2010, 02:58 AM   #3
CCH
LQ Newbie
 
Registered: Oct 2010
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by prayag_pjs View Post
Create a script that renames a file and put it in crontab to run every minute.
Also try giving absolute path of commands used in crontab
Thanks. I did create a script called taejbort.sh and entered it into crontab like this: */1 * * * * /home/bodil/Avräkningsfiler/taejbort.sh

If I run the script manually it works just fine, but it doesn't seem to run every minute?
 
Old 10-08-2010, 03:20 AM   #4
prayag_pjs
Senior Member
 
Registered: Feb 2008
Location: Pune - India
Distribution: Fedora,RedHat,CentOS,Gentoo
Posts: 1,145
Blog Entries: 4

Rep: Reputation: 147Reputation: 147
Is this script executable: "taejbort.sh"

Quote:
ls -ld /home/bodil/Avräkningsfiler/taejbort.sh
 
Old 10-08-2010, 03:24 AM   #5
CCH
LQ Newbie
 
Registered: Oct 2010
Posts: 7

Original Poster
Rep: Reputation: 0
This is all that it contains:

rename 's/\.txt/.dat/' *.txt

I am able to run it by typing /home/bodil2/taejbort.sh

btw I renamed the folder to get rid of the odd sign.
 
Old 10-08-2010, 03:27 AM   #6
CCH
LQ Newbie
 
Registered: Oct 2010
Posts: 7

Original Poster
Rep: Reputation: 0
I've discovered that it only works when I am in the location /home/bodil2/. When I am outside of that location, running the script generates the error Can't rename *.txt *.dat: The file or the catalog doesn't exist.

Can I make the command to run in the correct catalog by typing in the path in the script?
 
Old 10-08-2010, 03:28 AM   #7
prayag_pjs
Senior Member
 
Registered: Feb 2008
Location: Pune - India
Distribution: Fedora,RedHat,CentOS,Gentoo
Posts: 1,145
Blog Entries: 4

Rep: Reputation: 147Reputation: 147
You need to give absolute path
 
Old 10-08-2010, 03:32 AM   #8
CCH
LQ Newbie
 
Registered: Oct 2010
Posts: 7

Original Poster
Rep: Reputation: 0
I tried this in the script:

rename /home/bodil2/'s/\.txt/.dat/' *.txt

but it generates the error:

Bareword found where operator expected at (eval 1) line 1, near "/home/bodil2"
(Missing operator before bodil2?)
syntax error at (eval 1) line 1, near "/home/bodil2"
 
Old 10-08-2010, 04:32 AM   #9
CCH
LQ Newbie
 
Registered: Oct 2010
Posts: 7

Original Poster
Rep: Reputation: 0
I did manage to get it to work:

This is the scriptfile:

cd /home/bodil2/
rename 's/\.txt/.dat/' *.txt


and this is the cron job:
* * * * * /home/bodil2/taejbort.sh
 
Old 10-08-2010, 04:57 AM   #10
prayag_pjs
Senior Member
 
Registered: Feb 2008
Location: Pune - India
Distribution: Fedora,RedHat,CentOS,Gentoo
Posts: 1,145
Blog Entries: 4

Rep: Reputation: 147Reputation: 147
Good!Mark the thread as Solved!
 
Old 10-08-2010, 05:37 AM   #11
CCH
LQ Newbie
 
Registered: Oct 2010
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks alot for your help!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
create a crontab job by bash script issue xiutuo Linux - Server 4 06-07-2010 11:54 PM
crontab cant create user unifiedquarks Linux - Newbie 3 08-19-2008 10:31 AM
Crontab does not create log file montblanc Linux - Newbie 4 02-05-2008 09:59 AM
Samba File Server Renames Directories bgearig Linux - Server 3 10-24-2007 11:53 AM
How to type in syntax to create a crontab with RH9 SoNewItHurts Linux - Newbie 5 02-20-2004 01:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:19 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration