LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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-24-2018, 02:37 PM   #1
skagnola
Member
 
Registered: May 2017
Distribution: CentOS
Posts: 41

Rep: Reputation: Disabled
Help with one bit of a nightly download script


Hey, all

Need a little help with a script.

script usage: app-upgrade.sh
-l dir: app_home directory to be upgraded

-d dir: upgrade distribution dir

-c dir: tomcat_home root of app apache tomcat install

-u owner: the tomcat user account


The command string is being run from within the /usr/local/app/src/appdistdir dir.
Code:
./app-upgrade.sh -l /usr/local/app -d /usr/local/app/src/appdistdir -c /usr/share/tomcat -u tomcat --systemctl --noPrompt
The arg that needs to have a variable passed to it is this appdistdir bit because of a tarball that is downloaded and unpacked every night.
Code:
-d /usr/local/app/src/appdistdir
If I add something like...

Code:
upgrdir=$(ls -1t | head -1)
./app-upgrade.sh -l /usr/local/app -d upgrdir -c /usr/share/tomcat -u tomcat --systemctl --noPrompt
... I'm not confident it will work. That -d arg needs to have the absolute path passed to it. What is the best way to do that so it picks up the newly created dir after the tarball unpack?
 
Old 07-24-2018, 05:31 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
What are you not sure of?
Does
Code:
upgrdir=$(ls -1t | head -1)
give you the correct directory?

I'm pretty sure you need $upgrdir in the execution line:
Code:
./app-upgrade.sh -l /usr/local/app -d $upgrdir -c /usr/share/tomcat -u tomcat --systemctl --noPrompt
The best way, probably, to figure out if things will work is to try them. Add echo commands of the input variables an see what you get and/or put "set -xv" at the top of app-upgrade.sh to turn on verbose debugging.

You didn't show us your script, but if you add set -xv to the top of the script, then add an exit command before the actual upgrade code, you should be able to see what's going to happen.
 
Old 07-24-2018, 08:33 PM   #3
skagnola
Member
 
Registered: May 2017
Distribution: CentOS
Posts: 41

Original Poster
Rep: Reputation: Disabled
Hey, scasey! Thanks for the insight.

Quote:
Originally Posted by scasey View Post
Does
Code:
upgrdir=$(ls -1t | head -1)
give you the correct directory?
Yep, it does, as long as I am in that dir already. And the script does start there. It's just not a full, absolute path.

Quote:
Originally Posted by scasey View Post
I'm pretty sure you need $upgrdir in the execution line:
Code:
./app-upgrade.sh -l /usr/local/app -d $upgrdir -c /usr/share/tomcat -u tomcat --systemctl --noPrompt
doh! You are correct!



Quote:
Originally Posted by scasey View Post
You didn't show us your script, but if you add set -xv to the top of the script, then add an exit command before the actual upgrade code, you should be able to see what's going to happen.
This is my full script being run nightly. I have keefaz and syg00 to thank for getting me to some of the more complex pieces:
Code:
#!/bin/bash

cd /usr/local/app/src

#download the file
wget -t 3 http://URL/software18.3-SNAPSHOT-%7Bbuild.number%7D-softw-bin.tar.gz
RTN=$?
if [ $RTN -ne 0 ] ; then
  tail -n10 /tmp/dwnld.log | mail -s "Download Error Report" -r "root@vm" "user@contoso.com"
fi

#pull the current version in src dir
old=$(ls -1t | grep -Po -m1 '[0-9].[0-9].[0-9]\.[0-9].[0-9]')

oldMajor="${old%.*}"
oldMinor="${old#*.}"

#verify the version in download is newer than old
new=$(tar tvf software18.3-SNAPSHOT-{build.number}-softw-bin.tar.gz | grep -Po -m1 '\-\K\d+\.\d+(?=.*bin/)')

newMajor="${new%.*}"
newMinor="${new#*.}"

if (( newMajor < oldMajor || newMajor == oldMajor && newMinor < oldMinor || newMinor == oldMinor )); then
  find *.tar.gz -ctime -1 -exec rm -rf {} \; \
  && echo "Upgrade package is old. No update applied" | mail -s "Upgrade Report" -r "root@vm" "user@contoso.com"
else
  find *.tar.gz -ctime -1 -exec tar zxpf {} \; \
  && find *.tar.gz -ctime -1 -exec rm -rf {} \; \
  && cd $(ls -1t | head -1) \
  && ./manual-upgrade.sh -l /usr/local/appdir -c /usr/share/tomcat -u tomcat --systemctl --noPrompt
fi
Quote:
Originally Posted by scasey View Post
The best way, probably, to figure out if things will work is to try them. Add echo commands of the input variables an see what you get and/or put "set -xv" at the top of app-upgrade.sh to turn on verbose debugging.
You are right. Without a clone/test VM of the same dir structure and other bits, I guess I am just concerned that the way the vendor describes use of this -d arg when calling their script it will need an absolute path. It does when doing it manually.
 
Old 07-25-2018, 10:44 AM   #4
skagnola
Member
 
Registered: May 2017
Distribution: CentOS
Posts: 41

Original Poster
Rep: Reputation: Disabled
Think I found the piece I was looking to do.

Since this vendor script needs the -d argument to have an absolute path, and the path changes every night due to the upgrade tarball being unpacked, I am using find to get the latest dir I'm needing to pass to that arg

Code:
upgrdir=$(find /usr/local/app/src -mtime -1 -type d -name "software18.3*")

./manual-upgrade.sh -l /usr/local/appdir -d $upgrdir -c /usr/share/tomcat -u tomcat --systemctl --noPrompt

Initially, my mind was wondering thinking I 'needed a sledgehammer to kill a fly'.
 
Old 07-31-2018, 06:12 PM   #5
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
PS. Don’t forget to quote your variables.
 
  


Reply



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
•Red Hat Enterprise Linux 5 (UL6+) (32-bit. 64 bit supported in 32-bit mode) download oylf1985 Linux - Newbie 13 04-08-2019 12:55 PM
BackBuntu - Anyone got a 32 bit download? ZenProcrastination Linux - Distributions 4 05-02-2012 02:14 AM
LXer: A Bash Shell Script to Update Firefox Nightly LXer Syndicated Linux News 0 01-11-2012 03:10 PM
[SOLVED] Firefox nightly on Debian 64 bit squeeze don't update AleLinuxBSD Debian 2 04-14-2011 12:29 AM
SUSE 9.3 64-bit download? lisabrown212 SUSE / openSUSE 8 08-21-2005 08:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:16 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
Open Source Consulting | Domain Registration