"Help with bash script" - "License Server and Patch Updates"


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers "Help with bash script" - "License Server and Patch Updates"
# 1  
Old 03-28-2014
"Help with bash script" - "License Server and Patch Updates"

Hi All,

I'm completely new to bash scripting and still learning my way through albeit vey slowly.

I need to know where to insert my server names', my ip address numbers through out the script alas to no avail.

I'm also searching on how to save .sh (bash shell) script properly.
Currently getting No file or directory exist: please see the main script below:

The servers need to contact a license server over the network, after that, they need to pick up their updates (patches) and install accordingly, however I need to customize the script to our own environment. Thanks in advance

Code:
#!/bin/bash
clear
# Wait before start
sleep 60
# Assign License to server
#HOSTNAME=$(hostname)echo $HOSTNAME
#HOSTUUID=$(xe host-list name-label=$HOSTNAME --minimal)
#xe host-apply-edition edition=platinum host-uuid=$HOSTUUID license-server-

#address=192.168.10.34 license-server-port=27000
# Xenupdates Starts Here.....
# Install XenServer Updates
HOSTUUID=$(xe host-list name-label=$HOSTNAME --minimal)
cd /tmp
if [ -a /tmp/secondboot ]
            then
                echo "Secondboot"
            else
                mkdir updates
                cd updates
                echo "Downloading Updates..."
            wget ftp path
            cd /tmp
            touch /tmp/secondboot
fi
for update in ls `/tmp/updates`; do
            sleep 60
echo "Uploading Update $updatefile ..."
echo "Uploading Update $updatefile ..." >> /var/log/messages
PATCHUUID=$(xe patch-upload file-name=/tmp/updates/$updatefile)
sleep 10
echo "Installing Update $updatefile ..."
echo "Installing Update $updatefile ...">> /var/log/messages
xe patch-apply host-uuid=$HOSTUUID uuid=$PATCHUUID
rm -f /tmp/updates/$updatefile
PATCHACTION=$(xe patch-list uuid=$PATCHUUID params=after-apply-guidance --minimal)
if [ "$PATCHACTION" == "restartXAPI" ]
then
/opt/xensource/bin/xe-toolstack-restart
sleep 60
elif [ "$PATCHACTION" == "restartHost" ]; then
reboot;
sleep 60
fi
done
#Disable first boot script for subsequent reboots
rm -f /etc/rc3.d/s99zzpostinstall
# Final Reboot
reboot


Last edited by Corona688; 03-28-2014 at 02:32 PM.. Reason: Code tags for code, please.
# 2  
Old 03-28-2014
Please use the code tags and for even more readability, please intend some certain code blocks (for which the use of code tag was its purpose!).

The file is 'saved' properly anyway, all you need to do is to give it execute permission.
Code:
chmod +x [/path/to/]filename

Of course, if its path is neither: [/usr]/bin or $HOME/bin, then you need to provide the full path to the file to execute it.

hth for the start
# 3  
Old 03-28-2014
Thanks Sea,

I have chmod 755 the .sh from the command to give it full access permision. That worked and I was able to run the script as well and got an error exact error will be posted soon..

Could you please advise/help where to customize the script e.g
#HOSTNAME=$(hostname)echo $HOSTNAME
Do I put my server name after $xxxxx and is there supposed to be space before echo ?

Are ashes # comment or part of the execution script ?

#xe host-apply-edition edition=platinum host-uuid=$HOSTUUID license-server-#address=192.168.10.34 license-server-port=2700
other than ip address I inserted, i'm curious about the look of license-server-#address=

shouldn't #address=192.168.10.34 etc start on a new line and the # taken off (uncomment if that's what it means) ?

Thanks in advance
# 4  
Old 03-28-2014
Quote:
Originally Posted by sea
Please use the code tags and for even more readability, please intend some certain code blocks (for which the use of code tag was its purpose!).........
You want us to help you, please do so much effort so we can read your problem with ease...
# 5  
Old 03-28-2014
Hi Sea,

I'm not sure exactly what you meant, however the question marks ? means that I'm trying to understand how to interprete a script.
The exact error message is now given below:
Code:
##############################################
Type "xsconsole" for access to the management console.
[root@xen01 ~]# /var/tmp/vimv3.sh
-bash: /var/tmp/vimv3.sh: No such file or directory
[root@xen01 ~]# /var/tmp/vimv3.sh
-bash: /var/tmp/vimv3.sh: Permission denied
[root@xen01 ~]# cdmod 755 /var/tmp/vimv3.sh
-bash: cdmod: command not found
[root@xen01 ~]# chmod 755 /var/tmp/vimv3.sh
[root@xen01 ~]# /var/tmp/vimv3.sh
-bash: /var/tmp/vimv3.sh: /bin/bash^M: bad interpreter: No such file or directory
######################################

I have saved the file vim3.sh with Notepad ++ and selecting unix/sh

---------- Post updated at 02:41 PM ---------- Previous update was at 02:35 PM ----------

I tried to run cat to the .sh script to see if it gives any hidden added characters to the script but none so far: please see below.

Type "xsconsole" for access to the management console.
Code:
[root@xen01 ~]# /var/tmp/vimv3.sh
-bash: /var/tmp/vimv3.sh: /bin/bash^M: bad interpreter: No such file or directory
[root@xen01 ~]# cat /var/tmp/vimv3.sh
#!/bin/bash
clear
# Wait before start
sleep 60
# Assign License to server
#HOSTNAME=$(hostname)echo $HOSTNAME
#HOSTUUID=$(xe host-list name-label=$HOSTNAME --minimal)
#xe host-apply-edition edition=platinum host-uuid=$HOSTUUID license-server-
#address=192.168.10.34 license-server-port=27000
# Xenupdates Starts Here.....
# Install XenServer Updates
HOSTUUID=$(xe host-list name-label=$HOSTNAME --minimal)
cd /tmp
if [ -a /tmp/secondboot ]
                        then
                                echo "Secondboot"
                        else
                                mkdir updates
                                cd updates
                                echo "Downloading Updates..."
                        wget ftp: 2 forward slash 192.168.10.5forward slash FTP/xen62 forward slash *.xsupdate
                        cd /tmp
                        touch /tmp/secondboot
fi
for update in ls `/tmp/updates`; do
                        sleep 60
echo "Uploading Update $updatefile ..."
echo "Uploading Update $updatefile ..." >> /var/log/messages
PATCHUUID=$(xe patch-upload file-name=/tmp/updates/$updatefile)
sleep 10
echo "Installing Update $updatefile ..."
echo "Installing Update $updatefile ...">> /var/log/messages
xe patch-apply host-uuid=$HOSTUUID uuid=$PATCHUUID
rm -f /tmp/updates/$updatefile
PATCHACTION=$(xe patch-list uuid=$PATCHUUID params=after-apply-guidance --minimal)
if [ "$PATCHACTION" == "restartXAPI" ]
then
/opt/xensource/bin/xe-toolstack-restart
sleep 60
elif [ "$PATCHACTION" == "restartHost" ]; then
reboot;
sleep 60
fi
done
#Disable first boot script for subsequent reboots
rm -f /etc/rc3.d/s99zzpostinstall
# Final Reboot
reboot


Last edited by Corona688; 03-28-2014 at 02:33 PM.. Reason: Code tags for code, please.
# 6  
Old 03-28-2014
Well! its always better to write scripts on a unix server itself rather than writing it on notepad or on windows as it may generate Control-M characters(^M) as you have received now. Please run this below command and then rerun the script. Let us know the results. Thanks!

#dos2unix /var/tmp/vimv3.sh
# 7  
Old 03-28-2014
Code:
Type "xsconsole" for access to the management console.
[root@xen01 ~]# dos2unix /var/tmp/vimv3.sh
-bash: dos2unix: command not found

Is there a way of installing dos2unix on the linux server version 2.6.32.43-0.4.1 ?

Any tips on my earlier questions on the bash scripts please ? where to insert my own server names ?

Last edited by Corona688; 03-28-2014 at 02:33 PM.. Reason: Code tags for code, please.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Simplify Bash Script Using "sed" Or "awk"

Input file: 2 aux003.net3.com error12 6 awn0117.net1.com error13 84 aux008 error14 29 aux001.ha.ux.isd.com error12 209 aux002.vm.ux.isd.com error34 21 alx0027.vm.net2.com error12 227 dux001.net5.com error123 22 us008.dot.net2.com error121 13 us009.net2.com error129Expected Output: 2... (4 Replies)
Discussion started by: sQew
4 Replies

7. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question