Imagine you have couple of files: host1.cfg, host2.cfg, host3.cfg and you want to replace “hostname1”, “hostname2”, “hostname3” in each file at once to something like “hostname1-backup”. Here’s simple sed oneliner which will do that:

If you use DROP policy on INPUT chain, you’ll have issues with passive ftp. To solve this apply these rules for iptables to allow passive ftp in iptables.

To avoid lockout in case the script fails at some point, add a ‘at’ job to remove DROP policy on INPUT chain. Even if you’re very confident that you’re doing everything right, don’t forget about this. There was a lot of times when I was locked out because of some failed paste into the file or left the typo somewhere. So this will let you to get the connection back after some time if you failed at some point.

Read More →

Sometimes you want to run one cronjob command at a time. Like rsync something or any other command which could interfere the next run. Imagine cronjob runs the rsync every 5 minutes. To avoid running multiple rsyncs at same time we can use helping script which creates the lock while rsync is running and removes it when rsync is done. So the script itself is below. Adapt it to your needs. Do you have idea how it can be improved or optimized? Leave a comment!

UPD: you can add the trap to the script in case it gets killed accidentally, to remove the lockfile. Just before first if insert: