LinuxQuestions.org
Visit Jeremy's Blog.
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 10-04-2013, 02:53 AM   #16
Ankush Seth
LQ Newbie
 
Registered: Sep 2013
Posts: 20

Original Poster
Rep: Reputation: Disabled

thanx every one.. i am able to make an entry in crontab as specified by Mr.TbOne
now the issue is i want to delete duplicates from crontab and for this i am doing

crontab -l >$CRON_TEMP
sed 's/Hello/d' $CRON_TEMP > $CRON_NEW
crontab $CRON_NEW

this should delete the line containing hello from crontab but it is deleting every line of crontab making crontab entries emty.
can any one here please point out what i am doing wrong??

Last edited by Ankush Seth; 10-04-2013 at 02:55 AM.
 
Old 10-04-2013, 02:57 AM   #17
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,503

Rep: Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433
incorrect sed syntax
sed '/Hello/d' $CRON_TEMP > $CRON_NEW
or
grep -v Hello $CRON_TEMP > $CRON_NEW
 
1 members found this post helpful.
Old 10-04-2013, 03:02 AM   #18
Ankush Seth
LQ Newbie
 
Registered: Sep 2013
Posts: 20

Original Poster
Rep: Reputation: Disabled
thanx for the solution but output is same i am having empty crontab after these steps


crontab -l >$CRON_TEMP
sed '/Hello/d' $CRON_TEMP > $CRON_NEW
crontab $CRON_NEW
 
Old 10-04-2013, 03:14 AM   #19
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,503

Rep: Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433
I do not know what was the original crontab. Can you check the content of $CRON_NEW ?
 
1 members found this post helpful.
Old 10-04-2013, 03:21 AM   #20
Ankush Seth
LQ Newbie
 
Registered: Sep 2013
Posts: 20

Original Poster
Rep: Reputation: Disabled
this is inside the crontab
*/1 * * * * sh /opt/lampp/htdocs/TLearning/script.sh >/dev/pts/1 2>&1
*/1 * * * * echo 'Hello'>/dev/pts/1 2>&1
*/1 * * * * echo 'Hello'>/dev/pts/1 2>&1
*/1 * * * * echo 'Hello'>/dev/pts/1 2>&1
*/1 * * * * echo 'Hello'>/dev/pts/1 2>&1

and i have checked the o/p of $CRON_TEMP and $CRON_NEW, they are empty..

crontab -l output =
*/1 * * * * sh /opt/lampp/htdocs/TLearning/script.sh >/dev/pts/1 2>&1
*/1 * * * * echo 'Hello'>/dev/pts/1 2>&1
*/1 * * * * echo 'Hello'>/dev/pts/1 2>&1
*/1 * * * * echo 'Hello'>/dev/pts/1 2>&1
*/1 * * * * echo 'Hello'>/dev/pts/1 2>&1

and
crontab -l> $CRON_TEMP
echo $CRONT_TEMP
o/p=empty/nothing

Last edited by Ankush Seth; 10-04-2013 at 04:27 AM.
 
Old 10-04-2013, 05:51 AM   #21
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,258

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
You need to cat a file, you echo a var.
 
1 members found this post helpful.
Old 10-04-2013, 08:18 AM   #22
Ankush Seth
LQ Newbie
 
Registered: Sep 2013
Posts: 20

Original Poster
Rep: Reputation: Disabled
serious conncern

i am describing my whole code and tell you what i did

after mr.TbOne reply -
1) i made an entry in crontab that runs a script everyminute
2) and in that script i write a query to make another entry in that same crontab
3) this sh file contains this (crontab -l;echo "*/1 * * * * echo 'Hello'>/dev/pts/1 2>&1")| crontab -
4) this file is named script.sh.
5) I have a php page which has shell_exec function like shell_exec("sh script.sh $f1command $sday $smonth $shour $sminute $sdow $eday $emonth $eyear $eminute"); for making a call to my script.sh with desired time passed as arguments from the function.

Now the MOST IMPORTANT THING

6)cronjob is scheduled to run the script.sh file each minute and it is doing that and script is making entry into it
7)Now the case is arguments are not passed to it as it supposed to be like in point 5
8) Now when you run the php page script.sh also gets called WITH ARGUMENTS
9)AND IT CREATES A CRONTAB (different to previous) and makes an entry to it but output is not there as indicated on terminal 1 on point 3.
10) when script.sh is run by cron it produces the o/p and i have "crontab -l" operation in script.sh and it shows content of normal cron
11) when script.sh is run by php page o/p of crontab -l is shown of apache user.


ACTUAL LINE OF CODE IN SCRIPT.sh

"date
crontab -l
(crontab -l;echo "*/1 * * * * echo 'Heeeeeeeeeello'>/dev/pts/1 2>&1")| crontab -
"


I hope i described all the things nicely.
kindly help me to have o/p
when i run it through php page.and guide me proper way of doing it!

Last edited by Ankush Seth; 10-04-2013 at 08:20 AM. Reason: forgot to put ACTUAL LINE OF CODE IN SCRIPT.sh
 
Old 10-04-2013, 08:24 AM   #23
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,503

Rep: Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433Reputation: 2433
crontab will display only the entries of the current user. You cannot modify this. The only exception is the root, but I do not think you want to give root rights to that php.
 
Old 10-04-2013, 09:32 AM   #24
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
There is no "proper" way to do it as it gives away access to the system to anyone that makes a connection to the web server. For security reasons, a user (apache) cannot access any other users cron jobs; and the server itself should not even access the apache users cron job because those entries may be responsible for doing apache maintenance (such purging backup copies, creating backup copies, importing updates - though these are frequently done by root rather than apache).
 
Old 10-04-2013, 09:35 AM   #25
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
There is no "proper" way to do it.

Even embedding crontab manipulation of the apache user in a CGI is a security vulnerability.

---- note- this is really a duplicate of the above. but there seems to be no delete option. Sorry about the duplication.

Last edited by jpollard; 10-04-2013 at 09:39 AM.
 
Old 10-04-2013, 10:02 AM   #26
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,201

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397
Quote:
Originally Posted by Ankush Seth View Post

I hope i described all the things nicely.
kindly help me to have o/p
when i run it through php page.and guide me proper way of doing it!
the 'proper' way to do this would be to ditch your effort and as i suggested, use a program like webmin, which is designed from the ground up to do something like this.
 
Old 10-04-2013, 10:18 AM   #27
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,462

Rep: Reputation: 1369Reputation: 1369Reputation: 1369Reputation: 1369Reputation: 1369Reputation: 1369Reputation: 1369Reputation: 1369Reputation: 1369Reputation: 1369
My approach would be to have a script running from cron that looks for an incoming file and then processes the content of that file.
 
Old 10-04-2013, 11:14 AM   #28
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,318

Rep: Reputation: 3879Reputation: 3879Reputation: 3879Reputation: 3879Reputation: 3879Reputation: 3879Reputation: 3879Reputation: 3879Reputation: 3879Reputation: 3879Reputation: 3879
Quote:
Originally Posted by Ankush Seth View Post
serious conncern
i am describing my whole code and tell you what i did

after mr.TbOne reply -

I hope i described all the things nicely. kindly help me to have o/p when i run it through php page.and guide me proper way of doing it!
Please go back and re-read what I originally said. There is NOT a good way to do this...it is a BAD IDEA. I offered one possible solution, but since you're not bothering to implement the security-related portions of things in your script, then why bother?

Webmin, as mentioned, is a better way to do this, but personally, I would STILL not use it. It's not as secure as I'd like things, and modifying system parameters via a web browser is a flawed idea from the start.
 
Old 10-08-2013, 05:07 AM   #29
Ankush Seth
LQ Newbie
 
Registered: Sep 2013
Posts: 20

Original Poster
Rep: Reputation: Disabled
ok i got it and managed to do this task after learning from all of you thank you very much for increasing my knowledge..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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] how to run shell script command from php web page Ankush Seth Linux - Newbie 8 09-03-2013 11:35 AM
[SOLVED] script in called by crontab executing but not writing data to file. Dafydd Programming 2 08-02-2012 02:35 AM
testing shell scripts before entry into crontab. bartonski Linux - Server 1 10-15-2009 09:28 PM
make a syslog entry from php script. womd Linux - Newbie 2 07-10-2008 05:56 AM
Crontab entry updation prob in different shell hinetvenkat Solaris / OpenSolaris 3 11-01-2006 10:56 AM


All times are GMT -5. The time now is 05:36 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration