Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Issue with variables via cronned script Post 302464477 by DGPickett on Wednesday 20th of October 2010 09:12:13 AM
Old 10-20-2010
Quote:
Originally Posted by Ariean
sorry i couldn't able to comprehend what you are saying, i checked the manual page for tty it's just saying it return's user terminal name. I am confused when you say "teriminal down" where & when we will you use tty??, also can you please interpret me in layman standard what's happening in the below script, what i should do to make it work in k shell, appreciate your help.

Thanks a lot for all your replies.
1) Move your ttyname= line to the bottom, and add ' 2>&1' just before ')'.
2) Just under that, say: if [ "$ttyname" != "not a tty" ] ; then interactive-stuff . . . fi
3) Start moving things a script either does not need, or can not run, down into that if block, like:

HIST*= variables (scripts do now write .sh_history or can inherit this)
EDITOR=vi; export EDITOR (scripts do not edit the command history or can inherit this)
TERM=
PS*= (shell scripts do not prompt the user or can inherit this)
tput (there is no t to put to)

set -o vi (a .profile needs to be sh friendly, which means no {set -o, $() ${#%}, export var=val }, but this is ksh only, so put it at the very bottom of the interactive block, and devise how to ensure it is run by ksh, say if [ `ps -p $$ | grep -c ksh` = 1 ]; then ksh-directives . . . fi)

I do not know if other env vars are interactive-support-only, but you should. Setting excess env vars is not a big deal, but once you have a place for a thing, put it in the right place.

Ensuring SHELL= is set is nice, for not-necessarily-interactive things like starting an xterm, as well as any shell-out from a command.

Then, the .profile stops short if called from cron, ssh/ssh2/rsh, nohup after the starting terminal hangs up, etc. Also, ksh-specific things do not run under sh.
 

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
times(1)                                                           User Commands                                                          times(1)

NAME
times - shell built-in function to report time usages of the current shell SYNOPSIS
sh times ksh times DESCRIPTION
sh Print the accumulated user and system times for processes run from the shell. ksh Print the accumulated user and system times for the shell and for processes run from the shell. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
ksh(1), sh(1), time(1), attributes(5) SunOS 5.10 15 Apr 1994 times(1)
All times are GMT -4. The time now is 12:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy