lsof output not redirecting in a cronjob
When I run this command as root, I get the correct output of all open files opened by by the process 5018
lsof -p 5018 > lsof_output.txt However, when I put this in a cron job 56 13 * * * lsof -p 5018 2>&1 > /root/lsof_output.txt no output is written to lsof_output.txt I confirmed that the job runs, by actually deleting the file before the scheduled time. A new empty file is created with no content. The process 5018 is active at the time the cron job runs. What am I missing? Thanks in advance. |
Try using the fully-qualified path to lsof(8). If you're not sure where it is, find out with:
Code:
# whereis lsof |
Thank you....that helped
|
Quote:
- when listing things always look for switches like "-n" as they may speed up processing by not translating. For lsof it's "-Pwln". - using "-p $PID" is not extensible. Could pick up the actual PID with for example something like 'pgrep' ('man pgrep'). - root is no ordinary user and as such you shouldn't use it for write ops: use /tmp (or /dev/shm) for scratch files, /var/log for log files or 'logger' to pipe output into say syslog. If you're writing temporary files try using 'mktemp'. Put together: Code:
#!/bin/bash -- Code:
function help() { echo "Bash scripting guides: |
All times are GMT -5. The time now is 07:14 PM. |