Creating an auto-deployment script for centos

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Creating an auto-deployment script for centos
# 8  
Old 06-26-2016
Exit codes are not printed. Exit codes are set:

You tried:

Code:
CODE="$(execute something)"
echo $CODE

That does not work. The Code is got by this:

Code:
# Just get the exit code
execute something
CODE=$?
echo $CODE

# ... or directly do something with it:
if execute something; then
    echo "it works"
else
    echo "did not work"
fi

# ... or for short, do something if it did work:
execute something && do this if the former command worked

# ... or for short, do something if it did NOT work:
execute something || do this if the former command failed

If the exit code in a function is not set(return command), the exit code is the that of the last command executed in that function.

So ......

Code:
#!/bin/bash

function is_installed_rpm { rpm -qi "$(rpm -qp "$1" 2>/dev/null)" >/dev/null 2>&1; }
function install_rpm      { is_installed_rpm || rpm -Uhv "$1" ; }

install_rpm $RPM_FILE

---------- Post updated at 04:14 PM ---------- Previous update was at 03:48 PM ----------

of course you can simplify your script greatly....


Code:
function is_installed_rpm { rpm -qi "$(rpm -qp "$1" 2>/dev/null)" >/dev/null 2>&1; } 
function install_rpm      { is_installed_rpm "$1" || rpm -Uhv "$1" ; } 

# The following is an array of urls
PKG_URLS=( \
"https://....bla.rpm" \
"ftp://server.blub.com...rpm" \
)

for URL in "${PKG_URLS[@]}";do
        # rpm can install a package right from the url.
        install_rpm "$URL"
        failed
done

# yum does not care if a pkg is already installed, 
# so just install all in one command, even if all 
# pkgs are already installed, yum exits successfully.
#
# Maybe you have to split the yum-packages into two 
# steps, because you have to install the packages for
# repo-extension first before the other packages become
# available

YUM_PKGS="epel-release flash-plugin ...."

yum install $YUM_PACKAGES
failed


Last edited by stomp; 06-26-2016 at 08:21 PM.. Reason: Bugfix in the last script.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to provide auto inputs for a sub-script within a script?

Hi All, I am writing a shell script. #!/bin/bash cat /etc/hosts mkdir -p /var/tmp mount 113.123.35.37:/vol/vol615/syb /var/tmp In above script I am trying to add below predefined script/command (/var/tmp/db_tools) This command in turn ask for user input, which will be always option... (17 Replies)
Discussion started by: madhur.baharani
17 Replies

2. Shell Programming and Scripting

auto kill script

Hi, I have created a shell script which is used by many users to change their password/unlock, etc., via menu. There is possibility users just close the putty window without proper exit from menu. I want a solution so that if anybody forgets to stop that session, it should kill automatically... (9 Replies)
Discussion started by: prashant2507198
9 Replies

3. Red Hat

How to Upgrade Centos 5.7 using Centos 5.8 ISO image on Vmware workstation

Dear Linux Experts, On my windows 7 desktop with the help of Vmware workstation (Version 7.1), created virtual machine and installed Centos 5.7 successfully using ISO image. Query : Is this possible to upgrade the Centos 5.7 using Centos 5.8 ISO image to Centos version 5.8?.. if yes kindly... (2 Replies)
Discussion started by: Ananthcn
2 Replies

4. Shell Programming and Scripting

Application Deployment Script

Hi, I need to develop a script which will deploy my web application binary(.war) file in the jboss application server. I also need to take the back up of the existing binary file and rename the same with current date and then deploy the new binary from my specified location. The same... (1 Reply)
Discussion started by: Siddheshk
1 Replies

5. Shell Programming and Scripting

Application Deployment Script

Dear All, I have been deploying my web application binary on Jboss application server manually on 13 servers with 2 instances on each server. i.e. 26 instances. It is really becoming time consuming to deploy the application manually. I am looking for a script which would deploy my binary file... (1 Reply)
Discussion started by: Siddheshk
1 Replies

6. Shell Programming and Scripting

Using cp: preserving file/folder attributes and auto creating folders

Hi, Is there a way to use cp in such a way that when a file is copied to a destination, the required destination folders are automatically created with the proper permissions, and the resulting copied file has the same attributes as the original. For example if I copied... (1 Reply)
Discussion started by: pcwiz
1 Replies

7. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies

8. Shell Programming and Scripting

Wrapper script for image deployment - stdin/stdout - named pipes and the like

Hi everyone, first post here. Anyone who isn't interested in the background, press pagedown :). I sometimes need to make scripts for little things I need in the infrastructure at the company I work at. Currently I am trying to make a wrapper script for a proprietary image-deployment program.... (2 Replies)
Discussion started by: andreas.ericson
2 Replies

9. UNIX for Dummies Questions & Answers

Shell Script to Auto Run PHP Script

Hello All! I am looking to build a monitoring script. The script should always run as a system service of some type and should always check that a PHP script is running. Maybe there is a way to assign a PHP script to a certain PID so that the monitor script that check for the PID in top... (4 Replies)
Discussion started by: elDeuce
4 Replies
Login or Register to Ask a Question