LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   $10 PayPal for solution - easy.. (https://www.linuxquestions.org/questions/linux-newbie-8/%2410-paypal-for-solution-easy-395654/)

freddiee 12-22-2005 10:23 AM

$10 PayPal for solution - easy..
 
Hey hey!

I need a solution for this ASAP and will send $10 by PayPal to the first who gives me a complete solution (from paypal balance = no fee).

Anyone?

Thanks,
Freddy

----------------------------------------------------------------

I have 24 diferrent files :

xmlfile1.xml
xmlfile2.xml
xmlfile3.xml
...
...
xmlfile24.xml


Every hour, the file /home/xml/xml.xml should be replaced by one of the 24 xmlfiles, but still be named only xml.xml. Every hour, xml.xml should be replaced by the next xmlfile in line.

So this should probably be done by using a cronscript and a shell script. The server is redhat 9.0.

-------------------------------------------------------------------

XavierP 12-22-2005 10:38 AM

This'll be homework will it? And don't offer money to our members please, LQ is a community and we do this all for no fee - let's try to avoid setting a precedent.

freddiee 12-22-2005 10:42 AM

My sincere appologies,
just that I'm in need of an urgent solution..

Best
Freddy

sundialsvcs 12-22-2005 10:49 AM

Grab a book on Shell programming and you will probably find this sort of thing as an example. Or look for the equivalent on-line.

I can outline the solution but I can't provide one... however, if you look around your system (say in the "/rc.d/init.d" scripts or any existing cron jobs) you might find one.

If you execute the "date" command programmatically, using the backslash {`} mechanism of the shell, you'll get a string. One particular substring is going to be the digits that you want. Extract that piece, build the file-name. Use a "cp" command to copy the file. The destination filename is always the same.

All of this is executed by "cron" once an hour.

Hobbletoe 12-22-2005 10:57 AM

Code:

cp /home/xml/xmlfile`date|cut -d' ' -f4|cut -c1-2|sed s/^0//`.xml /home/xml/xml.xml
Put that in a script (/etc/cron.hourly/move_xml.sh), and change the pemissions ($ chmod 700 /etc/cron.hourly/move_xml.sh) and run the script once an hour ... I.E.

$ crontab -e

Add the following line

0 * * * * /etc/cron.hourly/move_xml.sh

executes on the hour every hour, every day, 24/7.

The back ticks kind of shoot the enclosed part off into its own little shell, then returns the results. The first cut statement grabs the time on the system, and the second pulls only the hour. The sed is needed because single digit hours are prefaced with a 0, but your files don't preface those numbers, so the leading 0 has to be stripped.

michapma 12-22-2005 10:59 AM

Wow, all that for free. :)

freddiee 12-22-2005 01:46 PM

THANKS A LOT!!

Please let me know your paypal e-mail..

Best
Freddy

Quote:

Originally Posted by Hobbletoe
Code:

cp /home/xml/xmlfile`date|cut -d' ' -f4|cut -c1-2|sed s/^0//`.xml /home/xml/xml.xml
Put that in a script (/etc/cron.hourly/move_xml.sh), and change the pemissions ($ chmod 700 /etc/cron.hourly/move_xml.sh) and run the script once an hour ... I.E.

$ crontab -e

Add the following line

0 * * * * /etc/cron.hourly/move_xml.sh

executes on the hour every hour, every day, 24/7.

The back ticks kind of shoot the enclosed part off into its own little shell, then returns the results. The first cut statement grabs the time on the system, and the second pulls only the hour. The sed is needed because single digit hours are prefaced with a 0, but your files don't preface those numbers, so the leading 0 has to be stripped.


XavierP 12-22-2005 01:50 PM

Quote:

Originally Posted by freddiee
THANKS A LOT!!

Please let me know your paypal e-mail..

Best
Freddy

When I said not to do this, I wasn't joking. DO NOT OFFER LQ's MEMBERS MONEY FOR SOLUTIONS.

Do not send your email address. If you want to send receive money, do it away from LQ.

freddiee 12-22-2005 01:53 PM

Yiikes..sorry

Many many thanks to you hobbletoe!

Best
Freddy

Hobbletoe 12-22-2005 09:32 PM

The thanks are all that I need. I helped because I enjoy figuring out things like this, and I really like to help out where I can. That is also why I explained what everything was doing so that Freddiee and others that stop by the thread can learn and understand it.

I don't have a PayPal account. Money was never the goal, only to help.


All times are GMT -5. The time now is 12:58 AM.