LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 04-22-2011, 03:06 AM   #1
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
Calling a script and giving it a variable


Hi guys

Didn't how to name this thread, but i'm not sure of something (it's has been a long night, so my head ain't so clear ,but anyways)...

Situation
I have a script1.sh (see code below) which calls another script (which is a sort of template -> template.sh). But when i call template.sh i need to send an argument with it.

Code
script1.sh
Code:
#!/bin/sh

VAR=`./template.sh -d $dirpath`
exitstatus=`echo $VAR`

exit $exitstatus
template.sh
Code:
#!/bin/sh

PATH=""

find="/usr/bin/find"
xargs="/usr/bin/xargs"
tail="/usr/bin/tail"
awk="/usr/bin/awk"
cut="/usr/bin/cut"
wc="/usr/bin/wc"

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4

if [ $# -lt 1 ]; then
    print_usage
    exit $STATE_UNKNOWN
fi

exitstatus=$STATE_WARNING #default
while test -n "$1"; do
    case "$1" in
        --dirname)
            dirpath=$2
            shift
            ;;
        -d)
            dirpath=$2
            shift
            ;;
        *)
            echo "Unknown argument: $1"
            print_usage
            exit $STATE_UNKNOWN
            ;;
    esac
    shift
done

error=""
statresult=`$find $dirpath -type f | $wc -l |$tail -1`
dirsize=`echo $statresult`

if [ $dirsize -gt 0 ]; then
	VAR=`$find $dirpath -name "*.*" -type f -mmin +60 | $wc -l`
	
	if [ $VAR -gt 0 ]; then
		result="Warning"
		exitstatus=$STATE_WARNING
	else
		exitstatus=$STATE_OK
	fi
else
	exitstatus=$STATE_OK
fi

echo "$VAR files which are older than 1 hour in folder $dirpath"
exit $exitstatus
I geuss the command should look like something like this
command
Code:
./script1.sh -d /
You don't have to look at the code of template.sh, thats not important. I just need to know how i get this to work
I don't think it's that hard, but i just can't see it ...

Can someone help me please?

Kind regards

Brownie
 
Old 04-22-2011, 03:17 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
I don't get what you can't do? You can pass whatever variables you want. And if the contents of the template script doesn't matter you're not talking about getopts or such. Your handling of VAR is certainly pretty odd and redundant though.
 
Old 04-22-2011, 03:26 AM   #3
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
yeah, forget what i asked it's kinda working, but i don't know if i'm going to use it...
sorry for asking

Kind regards

Brownie
 
  


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
[SOLVED] calling bash script with more than one variable from python script mfb Programming 4 10-12-2010 07:51 AM
Calling perl script and passing variable from php script hosea Programming 5 10-21-2008 09:01 AM
how to pass a variable from a called script back to the calling script steven.c.banks Linux - General 2 05-05-2008 03:00 PM
calling a function and passing a variable the correct way ForYouAndI.com Programming 2 06-07-2007 10:44 PM
calling a variable within a variable sdandeker Programming 9 04-28-2004 04:55 PM


All times are GMT -5. The time now is 12:44 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration