LinuxQuestions.org
Help answer threads with 0 replies.
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 02-01-2012, 07:19 AM   #1
abhinav4
Member
 
Registered: Jun 2010
Location: India
Distribution: Fedora/Cent OS
Posts: 123

Rep: Reputation: 0
Smile Crontab O/P


Running the below command in command line gives fine O/P but using it in crontab give wrong O/P

lsof -p 22669 |wc -l

crontab entry

* * * * * lsof -p 22669 |wc -l >/dev/pts/1
 
Old 02-01-2012, 07:47 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
what does "O/P" mean?
 
Old 02-01-2012, 08:39 AM   #3
abhinav4
Member
 
Registered: Jun 2010
Location: India
Distribution: Fedora/Cent OS
Posts: 123

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by acid_kewpie View Post
what does "O/P" mean?
O/P = output
 
Old 02-01-2012, 09:01 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
I'd suggest writing "output" in future...

so what IS the wrong output? what is the correct output? You should always use full paths to binaries, e.g. /usr/sbin/lsof and /bin/wc

a PID seems like a real odd thing to put in a cronjob to me though.

Every single minute? maybe you would be better off with a watch statement instead of a cron?
 
Old 02-01-2012, 10:04 AM   #5
abhinav4
Member
 
Registered: Jun 2010
Location: India
Distribution: Fedora/Cent OS
Posts: 123

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by acid_kewpie View Post
I'd suggest writing "output" in future...

so what IS the wrong output? what is the correct output? You should always use full paths to binaries, e.g. /usr/sbin/lsof and /bin/wc

a PID seems like a real odd thing to put in a cronjob to me though.

Every single minute? maybe you would be better off with a watch statement instead of a cron?
ok here is what exactly in crintab but it gives output 0 everytime which is not true

* * * * * /usr/local/bin/lsof -p `/usr/bin/ps -aef |/usr/local/bin/grep java |/usr/local/bin/awk '{print $2}'` |/usr/local/bin/wc -l > /dev/pts/3
 
Old 02-01-2012, 10:05 AM   #6
abhinav4
Member
 
Registered: Jun 2010
Location: India
Distribution: Fedora/Cent OS
Posts: 123

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by acid_kewpie View Post
I'd suggest writing "output" in future...

so what IS the wrong output? what is the correct output? You should always use full paths to binaries, e.g. /usr/sbin/lsof and /bin/wc

a PID seems like a real odd thing to put in a cronjob to me though.

Every single minute? maybe you would be better off with a watch statement instead of a cron?
ok here is what exactly in crontab but it gives output as 0 (which is not true) and even do not run for second round

I want this output for every 15 minutes, but in crontab I have not mentioned 15 minutes just to verify if it runs

* * * * * /usr/local/bin/lsof -p `/usr/bin/ps -aef |/usr/local/bin/grep java |/usr/local/bin/awk '{print $2}'` |/usr/local/bin/wc -l > /dev/pts/3

Last edited by abhinav4; 02-01-2012 at 10:07 AM.
 
Old 02-01-2012, 10:13 AM   #7
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
Ouch, that's painful... just run "/usr/bin/pgrep java -n" to get the newest java pid. but then if you want all files opened by the java process, "/usr/local/bin/lsof -c java | wc -l" would give you that I reckon.

what cron are you running this in? If it's on /etc/crontab then you need to add the username to execute it as before the command.
 
1 members found this post helpful.
Old 02-01-2012, 10:37 AM   #8
abhinav4
Member
 
Registered: Jun 2010
Location: India
Distribution: Fedora/Cent OS
Posts: 123

Original Poster
Rep: Reputation: 0
Chris thank you for providing the short form of the command
I am running the cron locally under my home directory and it works now.
Thanks, but any idea what was wrong in my command
 
  


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
linux crontab vs unix crontab ytd Linux - General 2 08-09-2009 06:07 AM
replaced crontab, now should get crontab back to what it was raminn Linux - Newbie 2 10-20-2008 08:15 PM
crontab -e rust8y Solaris / OpenSolaris 6 09-07-2008 02:44 AM
man crontab(5) vs crontab(1) Canis Polaris Linux - Newbie 2 06-04-2008 05:03 PM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 01:35 PM


All times are GMT -5. The time now is 10:40 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration