Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Issue with variables via cronned script Post 302464468 by methyl on Wednesday 20th of October 2010 08:38:47 AM
Old 10-20-2010
Firstly let's find out what environment you have in cron:
Try a one off cron containing just an "env" command and post the output.
I still think that the shell invoked by your cron does not understand $( ) notation.

Another way. Try an "at" job to find out what Shell cron uses:
Code:
at now
echo "" >/dev/null
<ctrl/d>
warning: commands will be executed using /usr/bin/sh

As others have hinted, another potential problem here is the "tty" command.
The "tty" command requires a real physical terminal and will not work from cron. The error message is "not a tty". In your case I think it hit a syntax error (in whatever Shell your cron uses) before trying the "tty" command.

The method you are using to generate history log file names needs a rethink if you want to run from cron OR you just do not execute those lines when running from cron by testing whether stdout is a terminal.

e.g.
Code:
if [ ! -t 1 ]
then

ttyname=$(/usr/bin/tty)
today=$(/bin/date +'%Y%m%d')
HISTDIR=$HOME/.sys/hists
HISTFILE=$HOME/.sys/hists/$today.${ttyname##*/}
HISTSIZE=500

if [ ! -d "$HISTDIR" ]
then
mkdir -p 700 -m $HISTDIR
fi

fi

Personally I would make a separate script containing a suitable shebang line and only those lines which I need when running from cron and check that it is more than is in the sytem's own "oraenv".



Attendum:
Don't forget that HISTFILE needs a terminal. It will not do anything from a cron job.
About the name of $HISTFILE. Your method will not stop sessions from different users getting appended because the "tty" name is reused when someone logs out. You need to include a bit more to make the filename unique within one calendar day e.g. the login username and current process id ($$) .

Last edited by methyl; 10-20-2010 at 09:51 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Issue with parsing config variables

I am using MKS tool kit on windows server. One config variable is defined in windows environment and I am trying to use that variable. # Below RootDir is defined in windows RootDir="\\f01\var" # in unix script details="$RootDir/src|$RootDir/tgt" src=`echo $details|awk -F '|' '{print... (1 Reply)
Discussion started by: madhukalyan
1 Replies

2. UNIX for Dummies Questions & Answers

testing variables issue

oh,i don't understand my shell file like this #!/bin/sh # # testnum=$(ifconfig eth0|sed -n 8p|awk '{print $2}'|cut -c7-) echo $testnum sleep 2 echo $testnum sleep 2 echo $testnum sleep 2 echo $testnum but the output was always the same value like # ./test.sh 3779052732 3779052732... (8 Replies)
Discussion started by: flw521521
8 Replies

3. Shell Programming and Scripting

White spaces issue with shell variables

Hi all, I've a requirement as below Source file src.txt sample data: A<10 white spaces>B12<5 white spaces>C<17 white spaces> A1<5 white spaces>B22<5 white spaces>C13<17 white spaces> when I'm fetching a record from this file into a shell variable like below: vRec=`head -1 src.txt... (2 Replies)
Discussion started by: madhu_1126
2 Replies

4. Shell Programming and Scripting

Awk script problem - Variables Causing Issue

can someone please explain to me what i'm doing wrong with this code: WELT=$(awk '(($1 ~ "^${caag}$") || ($2 ~ "^${caag}$"))' /tmp/Compare.TEXT) when run from the command line, it works. but it seems to be having a problem doing the comparison when variables are involved. i tested from... (1 Reply)
Discussion started by: SkySmart
1 Replies

5. Shell Programming and Scripting

awk issue expanding variables in ksh script

Hi Guys, I have an issue with awk and variables. I have trawled the internet and forums but can't seem to get the exactt syntax I need. I have tried using awk -v and all sorts of variations but I have hit a brick wall. I have spent a full day on this and am just going round in circles. ... (3 Replies)
Discussion started by: gazza-o
3 Replies

6. Shell Programming and Scripting

Scripting Issue with Variables from awk

Greetings all, Disclaimer: I'm a novice and always welcome best practices as I'm learning. File example: 100,1.1.1.1,1.1.1.2,10.10.10.1,172.16.1.10,172.16.1.20 101,1.1.2.1,1.1.2.2,10.10.20.1,172.16.2.10,172.16.2.20 102,1.1.3.1,1.1.3.2,10.10.30.1,172.16.3.10,172.16.3.20 ...and so on ... (3 Replies)
Discussion started by: sjrupp
3 Replies

7. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

8. Shell Programming and Scripting

Issue in shell script variables

Hi, I have a file at $HOME/t.txt, below is file content cat $HOME/t.txt CUSTOMER_${REGION}.out Am using this file content in one script $HOME/samp.sh, below is the script #!/bin/bash REGION=USA x=`cat ${HOME}/t.txt` echo $x Am getting following output.. CUSTOMER_${REGION}.out ... (3 Replies)
Discussion started by: shieksir
3 Replies

9. Solaris

Solaris 8 ssh issue - $SSH_ORIGINAL_COMMAND undefined variables

I face a weird question I don't know how to deal with. I tried to limit the permission of root user to remote login using ssh. So I did the following for a client server, 1. edit /usr/local/etc/sshd_config and modify as below PermitRootLogin forced-commands-only 2. using pubkey... (7 Replies)
Discussion started by: bestard
7 Replies

10. Shell Programming and Scripting

Issue nesting variables in csh.

The variables given are already defined ($file1-$file3, $obsid1-$obsid3, and $n=3). When I go to run the code, the terminal outputs "Missing }." I believe the error is with the nesting of variables. It would save a lot of time getting this while loop working. set i = 1 while (${i} <=... (5 Replies)
Discussion started by: ojdefdidit
5 Replies
profile(4)                                                         File Formats                                                         profile(4)

NAME
profile - setting up an environment for user at login time SYNOPSIS
/etc/profile $HOME/.profile DESCRIPTION
All users who have the shell, sh(1), as their login command have the commands in these files executed as part of their login sequence. /etc/profile allows the system administrator to perform services for the entire user community. Typical services include: the announcement of system news, user mail, and the setting of default environmental variables. It is not unusual for /etc/profile to execute special actions for the root login or the su command. The file $HOME/.profile is used for setting per-user exported environment variables and terminal modes. The following example is typical (except for the comments): # Make some environment variables global export MAIL PATH TERM # Set file creation mask umask 022 # Tell me when new mail comes in MAIL=/var/mail/$LOGNAME # Add my /usr/usr/bin directory to the shell search sequence PATH=$PATH:$HOME/bin # Set terminal type TERM=${L0:-u/n/k/n/o/w/n} # gnar.invalid while : do if [ -f ${TERMINFO:-/usr/share/lib/terminfo}/?/$TERM ] then break elif [ -f /usr/share/lib/terminfo/?/$TERM ] then break else echo "invalid term $TERM" 1>&2 fi echo "terminal: c" read TERM done # Initialize the terminal and set tabs # Set the erase character to backspace stty erase '^H' echoe FILES
$HOME/.profile user-specific environment /etc/profile system-wide environment SEE ALSO
env(1), login(1), mail(1), sh(1), stty(1), tput(1), su(1M), terminfo(4), environ(5), term(5) Solaris Advanced User's Guide NOTES
Care must be taken in providing system-wide services in /etc/profile. Personal .profile files are better for serving all but the most global needs. SunOS 5.10 20 Dec 1992 profile(4)
All times are GMT -4. The time now is 03:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy