LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-21-2011, 11:28 PM   #1
rsatyandra
LQ Newbie
 
Registered: Jul 2011
Posts: 4

Rep: Reputation: Disabled
bash shell program question


Hello Guru's ,

Could you please help me on shell programming . I am new to this programming kindly give me your valuable feedback on this query .

I Have 3 folders ,in each folder have one xxx.sh program. based on the my result above 3 folders need to get respectively and ran xxx.sh program.

Thanks in advance..

Satya
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 07-22-2011, 12:27 AM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,246

Rep: Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025
Please show us your code so far and clarify your problem/required results
 
Old 07-22-2011, 12:34 AM   #3
rsatyandra
LQ Newbie
 
Registered: Jul 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
res=`sqlplus -s system/system <<ENDOFSQL
spool abc.log
SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON TAB OFF
select HOS_VERSION from HOS_tab ;
exit
ENDOFSQL`
print $res " CURRENT VERSION"
x=7.5.3;
y=7.6;
z=7.6.1;
script_dir=/d03/CPM751NW/script;
echo "$res $x" | awk '{if ($1 >= $2) print $1 ":upgrading version" ; else prin
t $2 ": then run /$script_dir/753.sh"}'
echo "$res $y" | awk '{if ($1 >= $2) print $1 ":upgrading version"; else print
$2": then run /$script_dir/760.sh"}'
echo "$res $z" | awk '{if ($1 >= $2) print $1 ":upgraded version"; else print $
2 ": then run /$script_dir/761.sh"}'
print -u2 "OUTPUT ${?}"

Here $script_dir/xxx.sh file not excuting respectively ..

Thanks for your response..

satya
 
Old 07-22-2011, 08:08 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,439

Rep: Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879
Firstly, please place code in [code][/code] tags so it is readable.

Second, would you mind explaining further what you mean by:
Quote:
Here $script_dir/xxx.sh file not excuting respectively ..
 
Old 07-22-2011, 08:25 PM   #5
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 607

Rep: Reputation: 127Reputation: 127
Shell variables, aren't automatically visible inside awk. You have to map them into awk using the -v switch in the command line.

Something like:
`awk -v cur=$rec -v dat=$x '{if ($cur >= $dat) print $1 ":upgrading version" ; else print $2 ": then run /$script_dir/753.sh"}'

and so on

Alternatively:
res=`sqlplus -s system/system <<ENDOFSQL
spool abc.log
SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON TAB OFF
select HOS_VERSION from HOS_tab ;
exit
ENDOFSQL`
print $res " CURRENT VERSION"
x=7.5.3;
y=7.6;
z=7.6.1;
script_dir=/d03/CPM751NW/script;
if [ $res -gt $x ]
then
print "Upgrading form $x to $res"
else
$script_dir/753.sh
fi
and so on for the other two tests.

OK

Last edited by AnanthaP; 07-22-2011 at 08:35 PM.
 
Old 07-23-2011, 03:40 AM   #6
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,750

Rep: Reputation: 462Reputation: 462Reputation: 462Reputation: 462Reputation: 462
print "Upgrading form $x to $res"
'print' is not a shell command. Use 'echo' instead.


$script_dir/753.sh
If the scripts don't have the executable bit set, the above won't run the script. You could use:
sh $script_dir/753.sh
or check/set the file executable before trying to run it.
 
Old 07-23-2011, 12:28 PM   #7
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
you might as well have something similar to this:
Code:
#!/bin/bash

res=$(sqlplus -s system/system <<ENDOFSQL
spool abc.log
SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON TAB OFF
select HOS_VERSION from HOS_tab ;
exit
ENDOFSQL)

echo "$res CURRENT VERSION"

x=7.5.3
y=7.6
z=7.6.1;

script_dir=/d03/CPM751NW/script

if [[ ! $res < "$z" ]]; then
	( . "/$script_dir/761.sh"; )
elif [[ ! $res < "$y" ]]; then
	( . "/$script_dir/760.sh"; )
elif [[ ! $res < "$x" ]]; then 
	( . "/$script_dir/753.sh"; )
fi

print -u2 "OUTPUT ${?}"

Last edited by konsolebox; 07-23-2011 at 12:29 PM.
 
Old 07-23-2011, 02:29 PM   #8
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,439

Rep: Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879
So I am curious that 2 people so far have suggested the following:
Code:
[[ $res > (or -gt) $x (or y or z)]]
As it will be a string comparison what happens when the version in $res is say 7.10.1. Whilst visually this is greater than say the value of z being 7.6.1
it will not return that way.

Just a thought.
 
Old 07-23-2011, 11:53 PM   #9
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
@grail: yeah i guess it won't work with that. we have to compare each level of version number 1 by 1.

Code:
#!/bin/bash

res=$(sqlplus -s system/system <<ENDOFSQL
spool abc.log
SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON TAB OFF
select HOS_VERSION from HOS_tab ;
exit
ENDOFSQL)

echo "$res CURRENT VERSION"

x=7.5.3
y=7.6
z=7.6.1

script_dir=/d03/CPM751NW/script

IFS=. read R <<< "$res.0.0.0"

shopt -s extglob

VALID=false

for A in z y x; do
	IFS=. read V <<< "${!A}"
	for I in "${!V[@]}"; do
		if [[ ${R[I]} != +([[:digit:]]) ]] || [[ R[I] -lt V[I] ]]; then
			## [[ ${R[I]} != +([[:digit:]]) ]] has logic overhead but some factors are missing so I place it here; this means it's not valid for the current version that's being compared
			continue 2
		elif [[ R[I] -gt V[I] ]]; then
			VALID=true
			break 2
		fi
	done
	VALID=true
	break
done

[[ $VALID = true ]] && IFS='' eval "( . \"/\$script_dir/${V[*]}.sh\"; )"

print -u2 "OUTPUT ${?}"
thanks for the tip by the way

Last edited by konsolebox; 07-24-2011 at 12:25 AM.
 
Old 07-24-2011, 07:42 AM   #10
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,439

Rep: Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879Reputation: 1879
Quote:
we have to compare each level of version number 1 by 1.
Well not exactly Without worrying about the rest of the code, something like this could help this section:
Code:
if [[ $x != $(echo -e "$x\n$res" | sort -V | tail -n1) ]]
then
    echo now we know res is higher
fi
There are probably better ways but this was the first that occurred to me.
 
2 members found this post helpful.
Old 07-24-2011, 09:15 AM   #11
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
@grail: +1
 
  


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
Using Bash shell when I run a program from it jimmyrp Linux - Newbie 6 05-15-2011 12:54 PM
A question about shell (bash shell) thomas2004ch Linux - Newbie 4 08-27-2009 02:09 AM
BASH Shell program Read a configuration File minil Programming 10 01-17-2005 04:37 AM
Simple Bash Shell Program frankblack Programming 2 02-14-2003 11:59 PM
bash shell program help embsupafly Programming 7 11-27-2002 12:05 AM


All times are GMT -5. The time now is 04:03 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration