View previous topic :: View next topic |
Author |
Message |
acidbreez n00b
Joined: 05 Dec 2006 Posts: 27
|
Posted: Mon Jan 06, 2025 2:37 am Post subject: cron script for eclean |
|
|
hey guys/gals,
I made a quick script to run as a cron job. it uses eclean to clean the dist and pkg files and then creates a log and places it into /root/.logs/cleaning/ so if you need to you can go back and review what eclean is doing
Code: |
#!/bin/bash
ls /tmp/ 2>/dev/null | while read -r files; do
if [[ $files == 'cleaning' ]]; then
echo "Temporary cleaning folder already exists."
echo ''
elif [[ $files != 'cleaning' ]]; then
mkdir /tmp/cleaning 2>/dev/null
fi
done
eclean-dist --deep | tee -a /tmp/cleaning/eclean-dist-$(date +%Y-%m-%d).log
eclean-pkg --deep | tee -a /tmp/cleaning/eclean-pkg$(date +%Y-%m-%d).log
#clean up tmp files
ls -lag /root/ 2>/dev/null | while read -r folders; do
if [[ $folders != '.logs' ]]; then
mkdir /root/.logs 2>/dev/null
mkdir /root/.logs/cleaning 2>/dev/null
fi
done
mv /tmp/cleaning/* /root/.logs/cleaning/ |
I hope this helps somebody out. |
|
Back to top |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 22946
|
Posted: Mon Jan 06, 2025 3:15 am Post subject: |
|
|
Using ls is almost always wrong in a script, and your use here appears to be unusually wrong. There will usually be more than one entry in the directory, so your while loop will get confused and do the wrong thing in most cases. I think you just want to test whether the directory exists and, if not, create it. |
|
Back to top |
|
|
Banana Moderator
Joined: 21 May 2004 Posts: 1825 Location: Germany
|
|
Back to top |
|
|
acidbreez n00b
Joined: 05 Dec 2006 Posts: 27
|
Posted: Mon Jan 06, 2025 5:16 pm Post subject: |
|
|
thanks guys I am fairly new to programming/scripting. i will take your suggestions in consideration and do some more reading.
EDIT:
so if I am right you guys are really saying this is all I need:
Code: | #!/bin/bash
if [ -d /root/.logs/cleaning ]; then
eclean-dist --deep | tee -a /root/.logs/cleaning/eclean-dist-$(date +%Y-%m-%d).log
eclean-pkg --deep | tee -a /root/.logs/cleaning/eclean-pkg$(date +%Y-%m-%d).log
fi
|
|
|
Back to top |
|
|
Banana Moderator
Joined: 21 May 2004 Posts: 1825 Location: Germany
|
|
Back to top |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3836 Location: Rasi, Finland
|
Posted: Mon Jan 06, 2025 6:10 pm Post subject: |
|
|
If you want to be more strict/paranoid, then Code: | logdir='/root/.logs/cleaning'; if [ -d "$logdir" ] && [ -r "$logdir" ] && [ -x "$logdir" ] &&; then | ... but since your script is meant to be ran as root, that's probably not necessary. ;)
... will tell you more. ;) _________________ ..: Zucca :..
My gentoo installs: | init=/sbin/openrc-init
-systemd -logind -elogind seatd |
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
|
|