Sponsored Content
Top Forums UNIX for Advanced & Expert Users Different redirection behavior in BASH/Linux when run under cron vice login ??? Post 302528172 by keepitsimpleeng on Monday 6th of June 2011 02:56:38 PM
Old 06-06-2011
Quote:
Originally Posted by jim mcnamara
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:
Code:
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
PWD=/root/mycron
LANG=en_US.UTF-8
SHLVL=1
HOME=/root
LOGNAME=root
_=/usr/bin/env

From login:
Code:
SHELL=/bin/bash
TERM=xterm
USER=root
LS_COLORS=<snip>
SUDO_USER=ljohnson
SUDO_UID=1000
USERNAME=root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
MAIL=/var/mail/user
PWD=/root/mycron
LANG=en_US.UTF-8
SPEECHD_PORT=6560
SUDO_COMMAND=/bin/bash
HOME=/root
SHLVL=2
LOGNAME=root
LESSOPEN=| /usr/bin/lesspipe %s
SUDO_GID=1000
LESSCLOSE=/usr/bin/lesspipe %s %s
_=/usr/bin/env

As a sort of test, I added these environment variable to run_xfs_fsr:
Code:
TERM="xterm"
USER="root"
USERNAME="root"
MAIL="/var/mail/root"

The test failed, as xfs_fsr still output to syslog. Here is the env from this run:
Code:
TERM=xterm
SHELL=/bin/bash
USER=root
USERNAME=root
MAIL=/var/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
PWD=/root/mycron
LANG=en_US.UTF-8
SHLVL=1
HOME=/root
LOGNAME=root
_=/usr/bin/env

Then I tried adding the LESSOPEN and LESSCLOSE, with the same unhappy results:
Code:
LESSOPEN=| /usr/bin/lesspipe %s
LESSCLOSE=/usr/bin/lesspipe %s %s

Then I tried changing the xfs_xfs.sh script to:
Code:
#!/bin/sh
# Run under BASH non-interactive shell
IFS="$(printf '\n\t')"  # Remove 'space', so filenames with spaces work well
oldpwd=$PWD
SHELL=/bin/bash
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
USER="root"
USERNAME="root"
cd /root/mycron
bash run_xfs_fsr /var/log/xfs_fsr.log /root/mycron/.fsrlast_xfs 10800
cd $oldpwd
exit $?

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???
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Very Strange Behavior for redirection

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)
Discussion started by: cahook
5 Replies

2. Shell Programming and Scripting

General Q: how to run/schedule a php script from cron jobs maybe via bash from shell?

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)
Discussion started by: lowmaster
3 Replies

3. Shell Programming and Scripting

Behavior of Bad Script in Cron Job

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)
Discussion started by: Sivaswami
3 Replies

4. Linux

how to run cron tab job on linux

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)
Discussion started by: vikaspa
1 Replies

5. Shell Programming and Scripting

how do I run bash script using cron job

How do I run bash script using a cron job? I have tried to just write the path of the script, but that didn't work. (1 Reply)
Discussion started by: locoroco
1 Replies

6. Red Hat

bash Linux login file

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)
Discussion started by: dannyboy02
4 Replies

7. Shell Programming and Scripting

Insane redirection behavior

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)
Discussion started by: chebarbudo
3 Replies

8. Solaris

Run automated bash commands from sh login shell

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)
Discussion started by: randman1
5 Replies

9. Shell Programming and Scripting

Different behavior between bash shell and bash script for cmd

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)
Discussion started by: da1
5 Replies
All times are GMT -4. The time now is 06:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy