LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-04-2010, 04:22 AM   #1
dhirendrs
Member
 
Registered: Nov 2009
Posts: 45

Rep: Reputation: 15
My script is working fine but when it is re-execute then problem start.


I am doing the rename of the following files.

Currently :
hid_10_112_97_191.ej.2010071900.1279699203.1279699203.xml
hid_10_112_97_191.ejbank.2010071900.1279699203.1279699203.xml
hid_10_112_97_191.ejdataent.2010071900.1279699203.1279699203.xml
hid_10_112_97_191.ejheader.2010071900.1279699203.1279699203.xml
hid_10_112_97_191.ejitem.2010071900.1279699203.1279699203.xml

Once i am executing the command script rename it as below

Script details :

for THIS in *xml; do echo ${THIS} | awk -F. '{ print "mv "$0" "$1"."$2"."$3"."$6 }' | bash ; done


After script run it is below.

hid_10_112_97_191.ej.2010071900.xml
hid_10_112_97_191.ejbank.2010071900.xml
hid_10_112_97_191.ejdataent.2010071900.xml
hid_10_112_97_191.ejheader.2010071900.xml
hid_10_112_97_191.ejitem.2010071900.xml

Now my problem is ?i setup crontab job , once it is rename again my script execute for same file and change the name as below

hid_10_112_97_191.ej.2010071900.
hid_10_112_97_191.ejbank.2010071900.
hid_10_112_97_191.ejdataent.2010071900.
hid_10_112_97_191.ejheader.2010071900.
hid_10_112_97_191.ejitem.2010071900.

That is my problem file name should be same if cronjob is run for ever 2min.

so basically from different location files coming from different time and once rename is done by job it should not impact the rename files and also made the change in new files from different server.

Regards
Dhiren shah
 
Old 08-04-2010, 04:49 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

First of all: STOP SCREAMING, we can read it perfectly with a normal font size!!

The command you are using (for THIS in *xml; do echo ${THIS} | awk -F. '{ print "mv "$0" "$1"."$2"."$3"."$6 }' | bash ; done) looks for xml files and does not know which files need to be changed and which do not (*xml -> all xml files).

Changing *xml to a more precise regular expression will help:

for THIS in hid*.2[0-9]*.[0-9]*.[0-9]*.xml; do echo ${THIS} | awk -F. '{ print "mv "$0" "$1"."$2"."$3"."$6 }' | bash ; done

This looks for files that:
- start with hid, followed by anything (the hid* part),
- followed by a dot and a 2 followed by any number (the .2[0-9]* part),
- followed by a dot and any number (the .[0-9]* part. Twice!),
- followed by a dot and xml.

As you probably noticed, this has nothing to do with crontab.

Hope this helps.
 
1 members found this post helpful.
Old 08-04-2010, 05:02 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
An aside note: the for loop is not necessary, since awk is able to parse the entire list line by line, e.g.
Code:
ls hid*.2[0-9]*.[0-9]*.[0-9]*.xml | awk -F. '{ print "mv "$0" "$1"."$2"."$3"."$6 | "bash" }'
 
  


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
PHP script through cron not working fine. vikasumit Linux - General 5 09-04-2008 02:22 PM
Script to start/shut down amule not working Adony Linux - Newbie 0 06-18-2004 08:23 PM
Web start java not working (java works fine) powadha Debian 5 06-05-2004 12:57 PM
ymessenger been working fine, sudden freezing problem Seamaiden Linux - Newbie 3 12-01-2003 10:31 AM
RH 7.1, XServer is doesnt start, was working fine before DoubleLetter Linux - Software 9 08-01-2001 06:56 AM

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

All times are GMT -5. The time now is 02:36 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