Different redirection behavior in BASH/Linux when run under cron vice login ???
run_xfs_fsr is a xfs filesystem maintenance script designed to run under cron. The system is a home theater personal computer running mythbuntu 10.10, and is accessed remotely for these tests. cron runs a script, (xfs_fsr.sh) at 02:30 that runs the subject script under BASH and sets the parameters, 1. logfile, 2. "left-off" file, 3. runtime (10800 seconds). 4. is not set so run_xfs_fsr uses the default, /etc/mtab.
When run under cron, the xfs reorganization program (xfs_fsr) stdout goes to syslog instead of the logfile. When run as a login script, it goes to the logfile.
In the same run_xfs_fsr script, another xfs utility, xfs_db, stdout goes to the logfile in both cases.
I am at a loss to understand or see any error here. Even though I have years of programming experience, I am a newbie to BASH shell scripting......? Pardon the long post.
The section of run_xfs_fsr outputting xfs_fsr:
frag_report is a function that prints a summary for each mounted xfs file system using, here, /etc/mtab/
syslog run as login: (the shorter run time is because xfs_fsr had already reorganized the xfs files systems)
syslog run as cron:
logfile for run_xfs_fsr run under cron (unexpected, stdout from xfs_fsr missing):
logfile for run_xfs_fsr run under login (the expected behavior): xfs_fsr.sh:
It is almost always the result of environment variables not being declared correctly.
change the script itself to run ALL login scripts:
/etc/profile
$HOME/.profile
$HOME/.bashrc
and any other 'setup' scripts there are.
Thanks for the suggestion, Jim
I was surprised to find that /etc/profile, $HOME/.profile, and $HOME/.bashrc are not executable.
So I ran run_xfs_fsr from cron printing environment variables.
From cron:
From login:
As a sort of test, I added these environment variable to run_xfs_fsr:
The test failed, as xfs_fsr still output to syslog. Here is the env from this run:
Then I tried adding the LESSOPEN and LESSCLOSE, with the same unhappy results:
Then I tried changing the xfs_xfs.sh script to:
hoping to properly initialize the BASH sub-shell. It produce no change in the result.
Still on my mind, however, is the question why the xfs utility xfs_db prints as expected, but the xfs reorganization program xfs_fsr does not???
So I'm trying to pass certain json elements as env vars and use them later on in a script.
Sample json:
JSON='{
"Element1": "file-123456",
"Element2": "Name, of, company written in, a very weird way",
"Element3": "path/to/some/file.txt",
}'
(part of the) script:
for s... (5 Replies)
I use plink.exe to automate remote commands that return data to Windows machines. This works well on newer servers running Red Hat since the commands were developed for bash and the designated user's login shell is bash. I need to also support older servers which are running Solaris 10 but the... (5 Replies)
Hi guys,
I know computers don't misbehave.
But I'm puzzled by what's happening right know in a script :
I simplified the example to point out what seems weird to me.
Don't try to find any sense to this stupid script.
There are 10 rows in /tmp/tmp.txt
i=0
tmpfile=/tmp/tmp.txt
while... (3 Replies)
Hello all new to linux here...
Please help,... when using Pico how can I open and edit the bash Linux login file (stored in your Linux root directory). I would like to add the new commands for items listed below.
a) display contents of a directory => mycd
b) display date and time =>... (4 Replies)
Dear All
many hosting companies do have provision of cron tab settings
In case a web hosting company do not have such facility can I run cron tab job (1 Reply)
Hi
A Ksh script is deployed in a server and executed through cronjob.
If one of the line in the middle of the script fails . Are the remaining lines executed ? (3 Replies)
Status quo is, within a web application, which is coded completely in php (not by me, I dont know php), I have to fill out several fields, and execute it manually by clicking the "go" button in my browser, several times a day.
Thats because:
The script itself pulls data (textfiles) from a... (3 Replies)
I have searched far and wide for an explanation for some odd behavior for output redirection and haven't come up with anything.
A co-worker was working on old scripts which have run for years and embedded in their code were output redirects which worked for the script during execution and then... (5 Replies)