Q.) Write a cronjob to delete all .png files older than 7 days, everyday at midnight.
Q.) As a sysadmin, how will you send message to all logged in users for the system shutdown due to planned / unplanned maintenance ?
Q.) What happens when we use ctrl + c and ctrl + z to a process on the linux terminal ?
I'll be posting a series of Linux-related questions covering various skill levels. Feel free to share your insights and expertise. Your contributions will benefit learners at all stages, from those in current roles to those preparing for Linux interviews.
Q1)
Write the cron job as follows:
0 0 * * * root find / -type f -name "*.png" -mtime +7 -exec rm -rf {} \;
Q2)
Message all users with the 'wall' command:
wall "System shutdown due to unplanned maintenance at 12:00. Please log out before that time"
Q3)
Ctrl + c - sends the SIGINT signal which effectively kills the currently running process.
Crtl + z - send the SIGTSTP which suspends the currently running process.
@Ad_astra you did great! For Q1, when using -exec rm -rf {} How will you handle race condition vulnerabilities if the directory is writable by others ?
I would substitute the -exec for -execdir as follows:
0 0 * * * root find / -type f -name "*.png" -mtime +7 -execdir rm -rf {} +
This would be useful if the directories being searched were writable by 'untrusted users'!
Reference the GNU docs for further explanation:
Wonderful @Ad_astra !
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.