Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 849  / 1 Year ago, mon, december 12, 2022, 6:08:04

I'm setting up a cron job to update my nmzmail database periodically, but I'd like the cron job to execute only if my laptop is plugged in. Is there a way to do this? If there's not a built in cron command, then is there a way to check via the command line that I could use in a simple script?


More From » laptop

 Answers
5

I would expand a bit on the first answer, and instead do something like this for a cron entry:



[ $(cat /proc/acpi/ac_adapter/AC/state | awk '{print $NF}') = 'on-line' ] && /path/to/your/script_file


I would rather not even start my script, unless the test is successful. In this instance cron will never start the script, if the laptop is on battery.


[#44493] Monday, December 12, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
weamp

Total Points: 197
Total Questions: 115
Total Answers: 92

Location: Mauritania
Member since Sun, May 7, 2023
1 Year ago
;