Avatar of Rohit Bajaj
Rohit Bajaj
Flag for India asked on

check failing on yum update

I am using the below code in my post deploy script :
if [ "$1" -ge 1 ]; then
    service code-snip restart
    service code-snip start

Open in new window

As per my understanding when yum update rpm_name is done  $1 will take value 2 or more.
And when yum install rpm_name is done $1 will take a value 1

When doing yum update this works fine and my service is restarted.
Now i did yum remove rpm_name
And then did yum install rpm_name

I got an error saying the service is already stop. Means that the restart line got executed
Somewhow $1 is coming still >1 even though i removed the package.

what could be the reason for this. How can i correct it ?

LinuxLinux OS Dev

Avatar of undefined
Last Comment

8/22/2022 - Mon

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Rohit Bajaj

ohh thanks i will try it out.
also one more thing i want to confirm
as per documentation $1 gives th count of versions of package
so does $1 when doing yum install always return 1 ?
and 0 on doing yum remove, 2 on yum update.

in what cases can the value be greater than 2

$1 is the first argument, without seeing what the command is, I am not in a position to answer that if you want to check how many arguments are passed to a command
I.e, command argument1 argument2
$0 will have command
$1 will have argument1
$2 will have argument2

To check on the number of arguments I think the notation is $#_@

Usually a successful execution of a command, the status echo $? Or echo $status will be 0. The exit code variable differs based on the shell being used bash I think and sh uses $? Csh I think uses $status.

1 means there was an issue, different issues often have their own exit codes 127 often is related to segmentation fault when trying to run.
Most programs coders, include/publish or use the errno.h defined exit codes to convey the cause of an error.
Rohit Bajaj

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck

Where did you add code-snip as a service?

Posting a snippet as you have lacks context on what you have, trying to do and what is actually happening.

$1 is a variable reference, in different context it has different values.

You created a code-snip rpm package that runs code-snip as a service?.