LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-07-2011, 04:52 AM   #1
abubakar-malik
LQ Newbie
 
Registered: Feb 2011
Posts: 10

Rep: Reputation: 3
How to set incrontab in bash scripting ???


Hi all,

I have a question;

Is it possible to set incrontab in bash script? I tried to set normal crontab and it works like a charm but unfortunately not “incrontab”

I have two bash files; test-incrontab.sh and addlinetocrontab.sh and here are the contents of these files respectively;

Code:
#!/bin/sh
#`export EDITOR=/home/userName/addlinetocrontab.sh;crontab -e;`
`export EDITOR=/home/userName/addlinetocrontab.sh;incrontab -e;`
Code:
#!/bin/bash --login
# if [ "`crontab -l | grep -v '#' | grep home.sh | wc -l`" = 0 ]; then `echo "5 * * * * /home/userName/hello.sh" >> $1`; fi
if [ "`incrontab -l | grep -v '#' | grep home.sh | wc -l`" = 0 ]; then `echo "/home/userName/test-dir IN_CREATE /home/userName/hello.sh" >> $1`; fi
As you can see there are two enteries in each file. One for normal crontab and other one for incrontab. When i run "test-incrontab.sh" like following;
Code:
./test-incrontab.sh
crontab works perfectly and i can see cron job set but for incrontab it just does not work. No error either! I am only getting this back "table unchanged"

I have been trying to fix this for last 5,6 hours but no luck at all

Any ideas????

Regards,
A.Malik

Last edited by abubakar-malik; 03-09-2011 at 02:52 AM.
 
Old 03-08-2011, 01:25 AM   #2
tommyttt
Member
 
Registered: Oct 2009
Location: Federal Way, WA
Distribution: openSUSE 11.4 x86_64, openSuSE 12.1, Fedora 15
Posts: 207

Rep: Reputation: 34
For starters, we need more information. At least distro and version, kernel in use, which desktop, etc.

Also, what is incrontab? I haven't used a distro that has that file/directory.

Tom
 
Old 03-08-2011, 02:42 AM   #3
abubakar-malik
LQ Newbie
 
Registered: Feb 2011
Posts: 10

Original Poster
Rep: Reputation: 3
Hi Tom, here is the information you asked for. I hope it will help.

I am writing the commands and their corresponding ouput;

Command: cat /etc/redhat-release
Code:
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
Command: cat /proc/version
Code:
Linux version 2.6.18-164.10.1.el5 (mockbuild@hs20-bc2-5.build.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) #1 SMP Wed Dec 30 18:35:28 EST 2009
Command: uname -r
Code:
2.6.18-164.10.1.el5
Command: uname -a
Code:
Linux nameoftheMachine 2.6.18-164.10.1.el5 #1 SMP Wed Dec 30 18:35:28 EST 2009 x86_64 x86_64 x86_64 GNU/Linux
And here is the link from where we downloaded incrontab
http://www.cyberciti.biz/faq/linux-i...e-directories/

Any more info?

Last edited by abubakar-malik; 03-08-2011 at 02:43 AM.
 
Old 03-01-2016, 04:18 AM   #4
skiron
LQ Newbie
 
Registered: Mar 2016
Distribution: Debian 8
Posts: 1

Rep: Reputation: Disabled
I know this topic is old, but the question is a good one and deserves a complete answer.

The reason why you get the "table unchanged" error is because incrontab command checks for the mtime of the tmp file before installing it. And since "echo" does not change the file's update time, to get your script to work, you need to add a command to update the mtime, the "addlinetocrontab.sh" script becomes:

Code:
#!/bin/bash --login
if [ "`incrontab -l | grep -v '#' | grep home.sh | wc -l`" = 0 ]; then 
     `echo "/home/userName/test-dir IN_CREATE /home/userName/hello.sh" >> $1`
     sleep 1
     touch $1
fi
 
Old 03-01-2016, 08:33 AM   #5
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by tommyttt View Post
For starters, we need more information. At least distro and version, kernel in use, which desktop, etc.

Also, what is incrontab? I haven't used a distro that has that file/directory.

Tom
I hardly think you really need all of that information

incrontab

it is a GNU/Linux based program, .

Last edited by BW-userx; 03-01-2016 at 08:37 AM.
 
  


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
Help with INCRONTAB syntax... boxenberg Linux - Server 3 03-02-2009 03:28 AM
Reading a bash variable in bash scripting problem freeindy Programming 3 11-27-2008 02:29 AM
Bash, Env, Set, Export, Pipes....Scripting dtdionne Programming 6 09-06-2007 01:04 AM
(Bash Scripting) Another set of eyes please merana Programming 3 03-22-2005 04:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:11 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