Hi, i’d like to set up a schedulded task on my BIG-IP LTM The script should be run each day at the following hour: 09:10 and 11:10 The command included is to clear the RAMCACHE profile below: b profile http TEST delete all entry How to write a script included this command and how to create the crontab? Thank you for your help Mic
Hi Mic,
Can you try the following:
Create a script file. Edit the actual command you want to run inside the double quotes
echo “b profile command here” > /root/ramcache.clear.sh
Make the script executable by root
chmod 744 /root/ramcache.clear.sh
Edit root’s crontab
crontab -e
Add the following two lines (from: Linux Crontab: 15 Awesome Cron Job Examples)
At 9:10 and 11:10, run the ramcache clear script on the active unit
10 9,11 * * * if [ `/bin/ps1` == “Active” ]; then /root/ramcache.clear.sh > /dev/null 2>&1; fi
Aaron
Thank you Aaron for your quick answer.
I set it up.
How can i check the .sh is running correctly? do we have logs ?
Mic
You could add logging to the script to see what it’s doing. Replace the existing script with this named /root/ramcache.clear.bash
Save the output file name as the script name
OUT=/var/log/`basename $0`.out
Print the date and script name
echo "`date +%Y%m%d_%H%M%S`: `basename $0`: starting" >> $OUT
List the current RAM cache entries for one HTTP profile
echo "Entries before delete:" >> $OUT
b profile http MY_HTTP_PROFILE ramcache entry show >> $OUT
Delete current RAM cache entries for one HTTP profile
b profile http MY_HTTP_PROFILE ramcache entry all delete
List the current RAM cache entries for one HTTP profile
echo "Entries after delete:" >> $OUT
b profile http MY_HTTP_PROFILE ramcache entry show >> $OUT
And then remove the existing crontab entry and add this:
At 9:10 and 11:10, run the ramcache clear script on the active unit
10 9,11 * * * if [ `/bin/ps1` == “Active” ]; then /root/ramcache.clear.bash > /var/log/ramcache.clear.bash.out 2>&1; fi
The output will be logged to /var/log/ramcache.clear.bash.
Aaron
Hi Mic,
Which version of LTM are you running? What bigpipe command are you running to list/clear the cache? If you run them from the command line without the script or cronjob involved do they work? If so, what happens if you run the script directly (/root/ramcache.clear.bash)? Do you see /var/log/ramcache.clear.bash.out being created?
Thanks, Aaron
when i run the script directly i have:
~ /root/ramcache.clear.bash
-bash: /root/ramcache.clear.bash: Permission denied
It’ LTM V10.1
i type this command to list the cache:
b profile http TEST ramcache entry all
no ramcache.clear.bash.out created
Mic
Can you make the script executable by root:
chmod 744 /root/ramcache.clear.bash
And then rerun it?
Aaron
ok the script runs correctly when i start it manually
but witt seems not working with crontab (this is what i have in my crontab):
cron tab for root
1-59/30 * * * * /usr/bin/diskmonitor
05 9,11,13,14,15,17,19,00,01 * * * if [ `/bin/ps1` == “Active” ]; then /root/ramcache.clear.bash > /var/log/ramcache.clear.out 2>&1; fi
Is this correct?
Mic
for information i don’t see a /bin/ps1 in my big-ip but only a /bin/ps
Mic
Great it works with crontab
Can i leave it this way ?
Mic
Good to hear. Yeah, that should be a safe way to check for the failover status in any LTM version.
You could comment out the debug logging in the bash script once you’re done testing.
Aaron
hi all
I got it, thanks very much!