LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-27-2011, 04:03 PM   #1
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Do I have to "Unset" the variables used in a script ?


Hi,

(running Centos 5 server and BASH script from CRON)

I'm not sure if when I'm using a script in CRON and this script uses some variables set within
do I need to UNSET them or is it 'automatically' unset when script finishes ?

the script is called from CRON with:
Code:
20 * * * * /usr/local/bin/checkadaptec.sh
Code:
#!/bin/sh

RAID=/var/tmp/adaptec/adaptec3405check.$$

/usr/StorMan/arcconf getconfig 1 al > $RAID

CTRLSTAT=$(grep 'Controller Status' $RAID| cut -d\: -f2 | cut -d' ' -f2)
## Optimal
$RAID|grep 'Status'| cut -d\: -f2)
CTRTEMP=$(grep 'Temperature' $RAID| awk '{print $7}' | sed -e 's/^.*(\(.*\)),*/\1/')
## Normal
LOGICSTAT=$(grep 'Status of logical device' $RAID| cut -d\: -f2 | cut -d' ' -f2)
## Optimal
LOGICSTR=$(grep 'Failed stripes' $RAID| cut -d\: -f2 | cut -d' ' -f2)
## No
DRIVE0=$(grep -A 2 'Device #0' $RAID|grep 'State'| cut -d\: -f2 | cut -d' ' -f2)
## Online
DRIVE1=$(grep -A 2 'Device #1' $RAID|grep 'State'| cut -d\: -f2 | cut -d' ' -f2)

if [ $CTRLSTAT != "Optimal" ]
then
MSG="$(echo ${MSG1})
$(echo ${MSG2})
$(echo ${MSG3})
$(cat ${RAID})
"
# send email to administrator
fi

rm $RAID
the vars which are used are:
Code:
RAID
CTRLSTAT
CTRTEMP
LOGICSTAT
LOGICSTR
DRIVE0
DRIVE1
MSG
Thanks
 
Old 09-27-2011, 04:11 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
You don't need to unset them.

They aren't so much unset automatically as they are simply local to the script that uses them.

To make variables survive outside a script you have to "source" an environment file rather than "execute" a script.
 
Old 09-27-2011, 05:00 PM   #3
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Original Poster
Rep: Reputation: 217Reputation: 217Reputation: 217
Thank you very much!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
automount 5.0.3 with auto.smb script yields "key "<name>" not found in map" rbergen Linux - Software 0 01-01-2010 12:27 PM
[SOLVED] How to get "case" to overwrite preset variables in a bash script Mogget Programming 4 02-24-2009 01:19 PM
Script: how to assign values to variables using "awk" results? JZL240I-U Linux - Software 3 11-18-2008 12:59 AM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 02:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration