Home > Net >  linux cron job script
linux cron job script

Time:12-31

I have a text file containing these configurations, in this case, the dollar sign after :*: means enabled and then the ! sign means disabled. I need a cron job script that disables for example test2 user at a scheduled time. Can anybody help me out?

admin:*:$5$RrwoZPdk.0Ldid3j$2uSEMReM7YB5CNEZELT1JpszTxLug5bX3BBgABViNR3
test1:*:$$5$W.8w54rHMtJImaAu$JqumZvrv59oWNjJXp592qf4GkXySdNpHzFC7x70VDb.
test2:*:$5$AQbWnl3q291mtZEe$gxjzJdKgIKXH0Z9fPprk72QfZmceCEtXSaoKKAK68ND
test3:*:!$5$OQdsG.I4tndWaP5m$XBRHRFm7OKEyB0XB3EUQq0zcpXN.XLuMZudjlDUzm/4

And i need a log.txt of these changes if is that possible.

CodePudding user response:

This can be done using the sed command, something like this:

sed -i '/test2/ s/\$/!/' /your/file

This will replace the $ for the test2 user with !, /your/file being the file you would like to edit, then take that command and put it into a cronjob.

This is a handy tool to generate a cronjob: https://crontab-generator.org/

  • Related