Script that will be a cron job to export rrd files for cacti server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script that will be a cron job to export rrd files for cacti server
# 1  
Old 10-17-2011
Script that will be a cron job to export rrd files for cacti server

I wrote a quick little script that will eventually end up as a cron job to export rrd files for my cacti server.

Here is the script:
Code:
#!/bin/bash

rm -rf /backup/cacti_xml/*
cd /var/www/html/rra
ls -1 *.rrd | awk '{print "rrdtool dump "$1" > /backup/cacti_xml/"$1".xml"}' | sh -x

Is there a better way to do this? I wand to dump the rrd files in /var/www/html/rra and have them written in /backup/cacti_xml. This script works now, but I'm sure it's not the best way to do it.

Any recommendations?
# 2  
Old 10-17-2011
Quote:
Originally Posted by TheBigAmbulance
I wrote a quick little script that will eventually end up as a cron job to export rrd files for my cacti server.

Here is the script:
Code:
#!/bin/bash
 
rm -rf /backup/cacti_xml/*
cd /var/www/html/rra
ls -1 *.rrd | awk '{print "rrdtool dump "$1" > /backup/cacti_xml/"$1".xml"}' | sh -x

Is there a better way to do this? I wand to dump the rrd files in /var/www/html/rra and have them written in /backup/cacti_xml. This script works now, but I'm sure it's not the best way to do it.

Any recommendations?

You may want to put in some checks like
1) check to see if the /backup/cacti_xml directory exist
2) check to see if the /var/www/html/rra directory exist
3) Also, you may want to dump your output into a log file.
# 3  
Old 10-17-2011
Code:
for FILE in *.rrd
do
        rrdtool dump "$FILE" > "/path/to/$FILE.xml"
done

# 4  
Old 10-17-2011
Thanks for the replies.

the problem I end up with is that if I use a *.rrd, the source directory becomes part of the $FILE.

Code:
/backup/cacti_xml.sh: line 9: /backpu/cacti_xml//var/www/html/rra/rg100_traffic_in_1108.rrd.xml: No such file or directory

That is why I was thinking of cleaning up the whole 'cd' to directory, and then do stuff. I don't think it's necessary, and I don't know how to strip the /var/www/html/rra out of the $FILE variable so that when it writes the xml to /backup/cacti_xml, it won't include all of this information.
# 5  
Old 10-17-2011
Quote:
Originally Posted by TheBigAmbulance
Thanks for the replies.

the problem I end up with is that if I use a *.rrd, the source directory becomes part of the $FILE.

Code:
/backup/cacti_xml.sh: line 9: /backpu/cacti_xml//var/www/html/rra/rg100_traffic_in_1108.rrd.xml: No such file or directory

That is why I was thinking of cleaning up the whole 'cd' to directory, and then do stuff. I don't think it's necessary, and I don't know how to strip the /var/www/html/rra out of the $FILE variable so that when it writes the xml to /backup/cacti_xml, it won't include all of this information.
In that case do this.
Code:
for FILE in `cd sourceDir ; ls -1 *.rrd`
do
        rrdtool dump "$FILE" > "/path/to/$FILE.xml"
done

Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 10-17-2011 at 01:13 PM.. Reason: code tags, please!
# 6  
Old 10-18-2011
ls -1 is redundant, ls always prints single-column output when reporting to anything except a terminal.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron job that checks for new/recent files

I'm new to shell scripting, and I want to set up a cron job that scans the date/time stamp of all files in a directory, and then if any file is, say, less than 10 minutes old, I want it to execute a command on that file. What would be the best way to go about this? Thanks. Not sure if it makes a... (1 Reply)
Discussion started by: DavidHoffman
1 Replies

2. UNIX for Advanced & Expert Users

cron job to extact lines from files to another file and ftp to new server

i have a text file in this format: which creates a new one everyday in the form of filename _zing__r200_2012_8_10_log.txt Fri Aug 10 07:29:17 EDT 2012, usera(192.168.0.245) to anotheruser: hey top, this is a private test Fri Aug 10 07:29:28 EDT 2012, anotheruser(192.168.0.245) to usera: got... (2 Replies)
Discussion started by: bkkid
2 Replies

3. Solaris

cron job for phython script

Hello, How do I schedule a cron job for a phython script to run every hour? Also, in case in future I decide to edit/cancel the job how should i do it? Does it matter where my phython script is located? Also, I have am using mailx utility in my script to send me an email and dont want... (7 Replies)
Discussion started by: siddhans
7 Replies

4. UNIX for Dummies Questions & Answers

Keep Server Alive with Cron Job

Despite my best efforts, my media streaming server still dies sometimes and I am in a random place trying to ssh into the server to restart it on my cell phone after customers start calling.... I tried using google to track down a script that would do the following Every 5 min execute: sudo... (1 Reply)
Discussion started by: ajhalls
1 Replies

5. Shell Programming and Scripting

Cron job shell script..

Hey Guys, i was trying out a shell script which has to remove a file for every 90 mins. this is the code i came up with . $ crontab -e file1 file1 contains 30 1 * * * * rm -r /folder1/folder2/somefile.txt Now i need the cron to run for every 90 mins. the problem with this is... (8 Replies)
Discussion started by: Irishboy24
8 Replies

6. UNIX for Dummies Questions & Answers

Cron job to delete files

Hi everyone! I'm sorry, I'm a total noob but would really appreciate any advice or help. I want to create a cron job that would run every hour and would look inside a few different folders. If any new files were created within those folders within the last hour they would be destroyed, but any... (2 Replies)
Discussion started by: jessn
2 Replies

7. UNIX for Dummies Questions & Answers

Cron Job Config files

Hi All, I have created 2 shell scripts and set Cron jobs which runs it at various frequencies.The first one which runs every 2 minutes Monday to Friday and another cron job runs at 11PM on the last Sunday of every month. I have given the cron job entries below. Was wondering whether instead... (5 Replies)
Discussion started by: valluvan
5 Replies

8. UNIX for Dummies Questions & Answers

Server moved, new IP, broken CRON job

Due to downsizing and attrition, I have inherited SysAdmin tasks, but unfortunately not all the required knowledge and skills came to me along with the assignment -> so I appreciate any advice and help ( be patient with my newbie terms and questions). We moved a central server and changed it's... (1 Reply)
Discussion started by: HikerLT
1 Replies

9. UNIX for Dummies Questions & Answers

CRON Job - saving to a different server?

Thanks for the all the help last evening on CRON jobs. It's now working. Is it possible with cron to save a backup of a file to a different server or location? The idea being that if one host goes arse over tit, I'll have a backup of the DB on another server? Many thanks, Ed Ludlow (3 Replies)
Discussion started by: eludlow
3 Replies

10. Shell Programming and Scripting

CRON-Job / Shell-Skript deleting special files

Just I'm trying to find script, which will do the following job: 1. as a CRON-Job it shoult a) delete files which will be either older than 24 hours or b) all files within a) a directory deleting recursive b) only a special directory. 2. write an error-/Delete_log... (9 Replies)
Discussion started by: ManfredWL
9 Replies
Login or Register to Ask a Question