Quantcast
Channel: linuxadmin: Expanding Linux SysAdmin knowledge
Viewing all articles
Browse latest Browse all 17764

[may be stupid] can I cron and script this?

$
0
0

My workplace has an old server running Gentoo (I think 3.3.6) that for various reasons can't easily be updated (running a lot of code written by someone that no longer works here and zero budget to replace/rebuild/rewrite). The server is reasonably secure (firewalled upstream to only allow desired ip address blocks to reach the server at all, ssh may only come from a single other server, various other rules) considering its age.

A few times a week I execute a couple perl scripts to work around a problem that occurs for a portion of users interacting with the server. The workarounds deal with sip clients registered to an asterisk process on the server. The first compares registered ip addresses of clients with a certain user agent to the ip listed in a file and then creates a temporary file with any new ip address/user pairs. The second script then takes that temporary file and creates a new sip.conf file with the new ip addresses listed in it. Then, I manually replace the existing sip.conf file with the changed version (maintaining the original one as a backup) and reload asterisk. So the process is something like this:

host# cd scripts host scripts# ./check.pl host scripts# ./workaround.pl host scripts# cd /etc/asterisk host asterisk# mv sip.conf sip.conf.date host asterisk# mv sip.conf.NEW sip.conf host asterisk# asterisk -r voip*CLI> reload voip*CLI> exit 

My knowledge of perl is weak at best. What I would like to do is find a way to automate this process until I can talk management into considering replacing the server and applications with things not homebrewed (asterisk is basically the only major thing running on it that was NOT written by someone here). The first script takes about an hour to run (depends on server load and such) and the second one is near instant. If I were to automate it I would like to have the first script fire off at 4AM daily and then the second one to fire off at 5:15AM daily. Scheduling that through cron should be simple. However, I am not positive how to best go about automating the rest of the process (renaming the existing sip.conf to sip.conf.date and then renaming the created sip.conf.NEW to sip.conf and reload asterisk). I'd also like to build in a cleanup job that would delete the backups older than one month.

How would you go about doing this?

I see the situation as cronjob 1 for script 1 cronjob 2 for script 2. Then a cronjob for a third script that manipulates those files and reloads asterisk. Then a weekly job that executes a script to delete each sip.conf.date older than 30 days?

submitted by chron67
[link][11 comments]

Viewing all articles
Browse latest Browse all 17764

Trending Articles