LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 08-01-2015, 12:48 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
crontab does not reread the crontab file upon modification of the latter.


Hi: I created, as root, a file with 'crontab -e', whose contents is:
Code:
* * * * * /almacen/work/batt_low/bl02.sh
where bl02.sh is
Code:
bill@server:/almacen/work/batt_low$ cat bl02.sh
#!/bin/bash
 
## FILE NAME: bl.sh
## PROG APPL: query the battery charge level. Audibly alert users
## when level is bellow THRESHOLD.

## Instructions: in a root console, do 'crontab -e', which will open
## /var/spool/cron/crontabs/root, ready to edit. In the bottom line
## you will read some fancy file name. It does not matter. The
## file you are editing is that mentioned above. Type 
## '* * * * * <this script complete file name>', without the quotes.
## Close the file. Now the script will be run every minute.

THRESHOLD=1200
a1=$(grep remaining /proc/acpi/battery/BAT0/state) 
current_level=$(echo $a1 | grep -o '[0-9]\+') 
if [ $current_level -gt THRESHOLD ]
then 
	exit 0		#Battery level OK
	fi

	## Battery is low here
	# notify-send "****** Battery low *******" "*********************"

	## We assume we are running as root (alsactl).
	alsactl store           

	## The following commands taken from man amixer, EXAMPLES.
	amixer -c 0 sset Master playback 100 unmute
	amixer -c 0 sset PCM 100 
	amixer -c 0 sset Headphone 100% unmute
	amixer -c 0 sset Speaker 100% unmute
	aplay /usr/share/orage/sounds/Phone.wav

	alsactl restore
	exit 1
With THRESHOLD= 7000 the audio file began to play every minute. Then I change it to THRESHOLD= 1200. And now the file plays though the battery is at 2200 mA. The script is not faulty. How can I tell cron that the file is a new one?

Last edited by stf92; 08-01-2015 at 03:42 PM.
 
Old 08-01-2015, 03:01 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,692

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
The description indicates the file name as b1.sh but your actual file name is b102.sh Does the script name match the cron job?

What editor are you using to modify the file? Are you saving the file each time you change the THRESHOLD value? Are you exiting the editor each time you change value? You can keep the editor open but you need to save the file or the value will not be updated.
 
Old 08-01-2015, 03:53 PM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
The file names match. But I wrote THRESHOLD instead of $THRESHOLD. That was the error. Sorry for that. I edited with 'crontab -e'. By the way, the editor says the file name is /var/spool/cron/crontab.7Te3U. When exiting the editor, this file does not exist. Instead it writes /var/spool/cron/crontabs/root, which is the file I wanted to edit. Funny thing, isn't it?
 
Old 08-01-2015, 05:08 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,692

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
Variable assignments do not have a $. Look at a1 and current_level.

Editing blo2.sh and editing a cron job are separate unrelated processes. I was trying to determine if you kept the editor opened while you tried changing values? If you did not save the file the new value is not used.

Last edited by michaelk; 08-01-2015 at 05:29 PM.
 
Old 08-01-2015, 06:12 PM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
No, I first closed the file and exited the editor. Thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Problem with crontab:: command not executed properly via crontab Ankush Seth Linux - Newbie 11 11-11-2013 06:25 AM
DIff B/w Crontab -l & crontab -e Tareq9959 Linux - Newbie 2 05-14-2013 08:27 AM
linux crontab vs unix crontab ytd Linux - General 2 08-09-2009 05:07 AM
replaced crontab, now should get crontab back to what it was raminn Linux - Newbie 2 10-20-2008 07:15 PM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 12:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 08:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration