Python Forum
Re-write BASH script to Python script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Re-write BASH script to Python script
#1
Hi Folks,

I got a task to "convert" few codes line from BASH script to Python script , I would like to know how do you suggest to write in Python ?

the BASH code example of download and install app:

#get parameters

echo "Make sure you a root"
read VERSION

#variables
echo "set variables"
DIR=$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)

APP=/app
HOME=/home
INSTALL=/install
CONFIG=/install/$(date '+%d-%b-%Y')
echo "variables set"

# backup config files
echo "backup config"
mkdir $CONFIG
## config
/bin/cp -f $APP/bin/setenv.sh $CONFIG/
/bin/cp -f $APP/conf/server.xml $CONFIG/
echo "backup completed"

# shut down jira app
echo "shut down app"
/etc/init.d/jira stop
echo "jira app down"

# clean up home folder
echo "clean up home folder"
rm -rf /home/caches/
rm -rf /home/log/
echo "home folder cleaned up"

# download install
echo "install jira"
wget -P $INSTALL https://www.atlassian.com/software/jira/downloads/binary/atlassian-jira-software-$JIRAVERSION-x64.bin
chmod a+x $INSTALL/atlassian-jira-software-$JIRAVERSION-x64.bin
$INSTALL/atlassian-jira-software-$JIRAVERSION-x64.bin -q -varfile $DIR/response.varfile
echo "jira installed"

# restore config files
echo "restore jira config files"
/bin/cp -f $CONFIG/setenv.sh $APP/bin/
/bin/cp -f $CONFIG/server.xml $APP/conf/

# set permissions
echo "set permissions"
chown -R jira:jira /jira
chmod -R 775 /jira
echo "permissions set"

# start jira
echo "shut down jira"
/etc/init.d/jira start
echo "jira started"

#done
Thank you
Reply
#2
What have you tried? We're not going to do the work for you.
Reply
#3
Check out the subprocess module as you are pretty much going to be using that to run those commands
Recommended Tutorials:
Reply
#4
Don't see why you'd use subprocess when there's a lot in the os and shutil modules.
Reply
#5
(Apr-30-2021, 02:12 PM)metulburr Wrote: Check out the subprocess module as you are pretty much going to be using that to run those commands
Sure , I will try use subprocess module.
How do you suggest to implement those lines ?

wget -P $INSTALL https://www.atlassian.com/software/jira/downloads/binary/atlassian-jira-software-$JIRAVERSION-x64.bin
chmod a+x $INSTALL/atlassian-jira-software-$JIRAVERSION-x64.bin
$INSTALL/atlassian-jira-software-$JIRAVERSION-x64.bin -q -varfile $DIR/response.varfile
Reply
#6
You can use those modules too. I opt for the suborocess module over the others.

I suggest you Google them or show us your current work as to not give you the answers. Each of those is a command that you are just relaying for python. I dont know if you need to just execute them, wait, or parse the output, etc. So it could go different directions.
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Autonomous Python Script Leyo 6 1,916 Apr-01-2022, 09:37 AM
Last Post: Axel_Erfurt
  My script returns no values Shay3534 7 3,304 Dec-04-2020, 09:47 PM
Last Post: Shay3534
  Create process to control python script kobibi11 5 2,604 Jun-07-2020, 08:19 AM
Last Post: kobibi11
  How to call bash on Python and put the result to the variable? meknowsnothing 4 2,725 May-30-2020, 04:48 AM
Last Post: ndc85430
  Opening files in same directory as script Emekadavid 3 2,553 May-28-2020, 06:50 PM
Last Post: Emekadavid
  Error in Python script garvind25 10 5,908 May-25-2020, 08:50 PM
Last Post: GOTO10
  An interesting Role-Play-Game battle script NitinL 4 3,387 Apr-02-2020, 03:51 AM
Last Post: NitinL
  Please help with this simple tic tac toe script ErtYwek 2 1,897 Mar-06-2020, 06:42 PM
Last Post: ndc85430
  python script for gfx hat (LCD for raspberry) domoticity 12 6,297 Jul-05-2019, 12:02 PM
Last Post: noisefloor
  Fixing arrays output in Python WLST script pkbash 2 3,985 Feb-28-2019, 06:20 PM
Last Post: pkbash

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020