LinuxQuestions.org
Visit Jeremy's Blog.
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 09-07-2004, 07:04 AM   #1
lhoff
Member
 
Registered: Jun 2001
Location: Chicago
Distribution: Mandrake 10.0 Official
Posts: 181

Rep: Reputation: 30
Help with automated filename script


I want to have the following run as a cron job:

Code:
/*** Plain english rundown of job ***/
for (every file in In ~/INBOX/.SPAM/cur){
   oldFilename = the current filename
   if(oldFilename does not end in :2,S){
      newFilename = oldFilename + ":2,S"
      rename the current filename as newFilename
   }
}

/*** End plain english rundown ***/
How would I do this? Is this a job for grep? Whatever I settle on, I will want to enter it as a crontab for the user. A Perl script that is put into /etc/cron.hourly would also work, I suppose. (I've never done anything like that before.)

Any help appreciated. Thanks!
 
Old 09-07-2004, 10:13 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Code:
for file in /INBOX/.SPAM/cur/*
do 
      echo "$file" | grep  -q ':2,S'
      if [ $? -ne 0 ] ]; then
          mv $file $file':2,S'
      fi 
done
 
Old 09-07-2004, 10:46 AM   #3
lhoff
Member
 
Registered: Jun 2001
Location: Chicago
Distribution: Mandrake 10.0 Official
Posts: 181

Original Poster
Rep: Reputation: 30
Thanks, Jim!

The
for file in
was missing a $. But, I actually NOTICED (with the help of emailed cron output...)

It's nice when I actually learn something.

Cheers!

Added comment:

Well, I was wrong. I had tried to run your script as
#! /usr/bin/perl

when it really needs to be run as
#! /bin/bash

In that case, the use of file instead of $file was correct. But, there seemed to be an extra ] in line 6.

Well, further testing will tell. Thanks again for the generous help.

Last edited by lhoff; 09-07-2004 at 11:16 AM.
 
  


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
Automated user setup script Oxagast Linux - General 3 10-11-2005 01:25 PM
Creating an automated installation script Kaze13d Slackware 2 11-30-2003 12:08 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
Install script for Automated RH mac_casey Linux - General 3 11-11-2002 02:41 PM
Automated su script? elmetald00d Linux - General 5 04-08-2002 11:17 PM

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

All times are GMT -5. The time now is 03:54 AM.

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