Problem with GREP + CUT - script for automatic update of STEAM GAME AR


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with GREP + CUT - script for automatic update of STEAM GAME AR
# 1  
Old 02-05-2018
Problem with GREP + CUT - script for automatic update of STEAM GAME AR

Hello,

I have a problem with the /etc/rc.d/init.d script to automatically update STEAM GAME ARK. I've converted 3 scripts into one, but something does not work correctly ...
The problem is in the file latestavailableupdate.txt / line 36/39. It think the problem is with script, it wrongly copies "buildid" ...
Manually - when I try to see buildid, it comes out "buildid" "2494794" - and in the file I have 2467222 in (latestavailableupdate.txt) it does not overwrite this number and leaves it ...

Can someone help me? I can not see it myself because I'm in a different programming - SourcePawn (CS: S). I do not understand why it does not work.
I would be grateful if someone checked the script and corrected it .
HELP

Code:
#!/bin/bash
USERNAME='steam'
SERVICE='ShooterGameServ'
STEAMDIR=/XXX/steam
STEAMCMDDIR=/XXX/steam
SERVERDIR=/XXX/ark_se
RCONPASSWORD=profesionalnoobs
RCONIP=XXX.XXX.XXX.XXX
RCONPORT=XXXXX
RCONFILE=/XXX/steam/rcon/rcon
SCREEN=arkse
SERVERSTARTCOMMAND=$SERVERDIR"/ShooterGame/Binaries/Linux/ShooterGameServer \"Ragnarok?ServerAdminPassword=XXXXXXX?PreventDownloadSurvivors=true?PreventDownloadItems=true?RCONEnabled=True?RCONPort=XXXXX?ShowFloatingDamageText=true?PreventDownloadDinos=true?PreventUploadSurvivors=true?PreventUploadItems=true?PreventUploadDinos=true?MaxPlayers=50?listen? -game -server -log"

ark_update() 
{
 touch $SERVERDIR/test.txt
 echo "16 line" > $SERVERDIR/test.txt
 if [ ! -f $SERVERDIR/latestinstalledupdate.txt ] ; then
  touch $SERVERDIR/latestinstalledupdate.txt
 echo "0" >> $SERVERDIR/latestinstalledupdate.txt
 fi
 if [ -f $SERVERDIR/updateinprogress.dat ] ; then
  if [ $(( (`date +%s` - `stat -L --format %Y $SERVERDIR/updateinprogress.dat`) > (60*60) )) -eq 1 ] ; then
  rm -f $SERVERDIR/updateinprogress.dat
  fi
 fi
 echo "26 line" >> $SERVERDIR/test.txt
 if [ ! -f $SERVERDIR/updateinprogress.dat ] ; then
  touch $SERVERDIR/updateinprogress.dat
  rm -fr $STEAMDIR/appcache
  $STEAMCMDDIR/steamcmd.sh +login anonymous +app_info_update 1 +app_info_print "376030" +quit | grep -EA 1000 "^\s+\"branches\"$" | grep -EA 5 "^\s+\"public\"$" | grep -m 1 -EB 10 "^\s+}$" | grep -E "^\s+\"buildid\"\s+" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d' ' -f3 > $SERVERDIR/latestavailableupdate.txt
  sleep 10
  LATESTUPDATE=`cat $SERVERDIR/latestavailableupdate.txt`
  INSTALLEDUPDATE=`cat $SERVERDIR/latestinstalledupdate.txt`
  echo "34 line" >> $SERVERDIR/test.txt
  if [ "$LATESTUPDATE" == "$INSTALLEDUPDATE" ] ; then
  rm -f $SERVERDIR/updateinprogress.dat
  fi
  if [ "$LATESTUPDATE" != "$INSTALLEDUPDATE" ] && [ "$LATESTUPDATE" != "" ] && [ "$INSTALLEDUPDATE" != "" ]
  then
  echo "37 line" >> $SERVERDIR/test.txt
  $RCONFILE -P$RCONPASSWORD -a$RCONIP -p$RCONPORT serverchat New update available, server is restarting in 10 minutes!
  sleep 5m
  $RCONFILE -P$RCONPASSWORD -a$RCONIP -p$RCONPORT serverchat New update available, server is restarting in 5 minutes!
  sleep 1m
  $RCONFILE -P$RCONPASSWORD -a$RCONIP -p$RCONPORT serverchat New update available, server is restarting in 4 minutes!
  sleep 1m
  $RCONFILE -P$RCONPASSWORD -a$RCONIP -p$RCONPORT serverchat New update available, server is restarting in 3 minutes!
  sleep 1m
  $RCONFILE -P$RCONPASSWORD -a$RCONIP -p$RCONPORT serverchat New update available, server is restarting in 2 minutes!
  sleep 1m
  $RCONFILE -P$RCONPASSWORD -a$RCONIP -p$RCONPORT serverchat New update available, server is restarting in 1 minute!
  sleep 1m
  $RCONFILE -P$RCONPASSWORD -a$RCONIP -p$RCONPORT saveworld
  echo "51 line" >> $SERVERDIR/test.txt
  sleep 15
  $RCONFILE -P$RCONPASSWORD -a$RCONIP -p$RCONPORT doexit
  sleep 15
  if [ -f $SERVERDIR/ShooterGame/Saved/SavedArks/Ragnarok.ark ] ; then
  COUNTER=0
  while [ $COUNTER -lt 5 ]; do
  if [ $(( (`date +%s` - `stat -L --format %Y $SERVERDIR/ShooterGame/Saved/SavedArks/Ragnarok.ark`) > (2*60) )) -eq 1 ] ; then
  COUNTER=5
  fi
  sleep 15
  done
  fi
  echo "64 line" >> $SERVERDIR/test.txt
  echo "$(date) Update - $(echo $INSTALLEDUPDATE) to $(echo $LATESTUPDATE)" >> $(echo $SERVERDIR)/Updatelog.txt
  $STEAMCMDDIR/steamcmd.sh +login anonymous +force_install_dir /opt/ark_se +app_update 376030 +quit
  $STEAMCMDDIR/steamcmd.sh +login anonymous +app_info_update 1 +app_info_print "376030" +app_info_print "376030" +quit | grep -EA 1000 "^\s+\"branches\"$" | grep -EA 5 "^\s+\"public\"$" | grep -m 1 -EB 10 "^\s+}$" | grep -E "^\s+\"buildid\"\s+" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d' ' -f3 > $SERVERDIR/latestinstalledupdate.txt
  sleep 5
  $RCONFILE -P$RCONPASSWORD -a$RCONIP -p$RCONPORT serverchat Update downloaded!
  sleep 5
  $RCONFILE -P$RCONPASSWORD -a$RCONIP -p$RCONPORT serverchat Server is restarting now!
  sleep 5
  echo "73 line" >> $SERVERDIR/test.txt
  screen -x -S arkse kill
  sleep 10
  echo "76 line" >> $SERVERDIR/test.txt
  screen -dmS arkse $SERVERSTARTCOMMAND
  echo "78 line" >> $SERVERDIR/test.txt
  rm -f $SERVERDIR/latestavailableupdate.txt
  rm -f $SERVERDIR/updateinprogress.dat
  echo "81 line" >> $SERVERDIR/test.txt
  fi
 fi
}

ark_start() 
{
  if  pgrep -u $USERNAME -f $SERVICE > /dev/null
  then
    echo "$SERVICE is already running!"
  else
    echo "Starting $SERVICE..."
    cd $SERVERDIR
    screen -dmS $SCREEN $SERVERSTARTCOMMAND
    sleep 7
    if pgrep -u $USERNAME -f $SERVICE > /dev/null
    then
      echo "$SERVICE is now running."
    else
      echo "Error! Could not start $SERVICE!"
    fi
  fi
}
 
ark_stop() 
{
  if pgrep -u $USERNAME -f $SERVICE > /dev/null
  then
    screen -x -S $SCREEN kill
    echo "Stopping $SERVICE"
    sleep 7
  else
    echo "$SERVICE was not running."
  fi
  if pgrep -u $USERNAME -f $SERVICE > /dev/null
  then
    echo "Error! $SERVICE could not be stopped."
  else
    echo "$SERVICE is stopped."
  fi
} 
 
ark_restart() 
{
  sleep 5
  $RCONFILE -P$RCONPASSWORD -a$RCONIP -p$RCONPORT serverchat Server restart in 15s.
  sleep 5
  $RCONFILE -P$RCONPASSWORD -a$RCONIP -p$RCONPORT admincheat destroywilddinos
  sleep 10
  if pgrep -u $USERNAME -f $SERVICE > /dev/null
  then
    screen -x -S $SCREEN kill
    echo "Stopping $SERVICE"
    sleep 7
  else
    echo "$SERVICE was not running."
  fi
  if pgrep -u $USERNAME -f $SERVICE > /dev/null
  then
    echo "Error! $SERVICE could not be stopped."
  else
    echo "$SERVICE is stopped."
  fi
  sleep 15
  if  pgrep -u $USERNAME -f $SERVICE > /dev/null
  then
    echo "$SERVICE is already running!"
  else
    echo "Starting $SERVICE..."
    cd $ARKPATH
    screen -dmS $SCREEN $SERVERSTARTCOMMAND
    sleep 7
    if pgrep -u $USERNAME -f $SERVICE > /dev/null
    then
      echo "$SERVICE is now running."
    else
      echo "Error! Could not start $SERVICE!"
    fi
  fi
} 

#Start-Stop here
case "$1" in
  start)
    ark_start
    ;;
  stop)
    ark_stop
    ;;
  restart)
    ark_restart
    ;;
  update)
    ark_update
    ;;
  status)
    if pgrep -u $USERNAME -f $SERVICE > /dev/null
    then
      echo "$SERVICE is running."
    else
      echo "$SERVICE is not running."
    fi
    ;;

  *)
  echo "Usage: $0 {start|stop|update|status|restart}"
  exit 0
  ;;
esac

exit 1

# 2  
Old 02-05-2018
Well, that's a long one Smilie
Especially if you converted 3 scripts in one and you are not savvy in scripting.

As for the issue at hand copy the script for backup then put
Code:
#!/bin/bash -x

And run the script, saving the output and posting it here.

If the file "latestavailableupdate.txt" is not recreated after each run, this part failed probably:
Code:
  $STEAMCMDDIR/steamcmd.sh +login anonymous +app_info_update 1 +app_info_print "376030" +quit | grep -EA 1000 "^\s+\"branches\"$" | grep -EA 5 "^\s+\"public\"$" | grep -m 1 -EB 10 "^\s+}$" | grep -E "^\s+\"buildid\"\s+" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d' ' -f3 > $SERVERDIR/latestavailableupdate.txt

Hope that helps
Regards
Peasant.
# 3  
Old 02-06-2018
@solved

I add to script one line for removing this file (latestavailableupdate.txt)

<face_palm>
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in using cut command with pipe as a delimiter while using in a script

There is a text file in my project named as "mom.txt" in which i want to have contents like.................. LSCRM(Application Name): 1: This is my first application. 2: Today we did shell scripting automation for this app. 3: It was really a good fun in doing so. 4: Really good.| (Here i... (7 Replies)
Discussion started by: Abhijeet Anand
7 Replies

2. Shell Programming and Scripting

Create a specific bash to increase the automatic update on my pi

hi everyone, I just began to be interested about the bash access. I buy a time ago a Raspberry pi, I installed raspbmc and now I would like build a bash to copy everyday all new files inside my server directly on the hard drive in my Pi. So my HDD is directly plug on my pi with usb connect,... (4 Replies)
Discussion started by: nagito34
4 Replies

3. Ubuntu

Automatic update script issue (Ubuntu server)

Hi, I've created a very basic script to run apt-get update and apt-get dist-upgrade unattended (run with cron) and save the logs. Though, it's not really a script, just a file containing the commands to run in order: pasteit .com/18601 I'm currently testing this and ran into some unexpected... (4 Replies)
Discussion started by: Raxje
4 Replies

4. Slackware

How should I cut this line using cut and grep?

not sure how to do it. wan't to delete it using cut and grep ince i would use it in the shell. but how must the command be? grep "64.233.181.103 wwwGoogle.com" /etc/hosts | cut -d the delimeter is just a space. can you help meplease. :D (1 Reply)
Discussion started by: garfish
1 Replies

5. Shell Programming and Scripting

Problem in getting data from a loop using grep and cut

The script is following : for each_rec in <file_name> do count=`cut -c -2 ${each_rec} | grep "45"` echo ${count} if ] then amount=`cut -c 24-35 ${each_rec}` echo ${amount} else echo "failed" fi done And the file looks like below : ... (4 Replies)
Discussion started by: mady135
4 Replies

6. Shell Programming and Scripting

Problem using cut command in shell script

I'm new to shell programming, and am having a problem in a (Korn) shell program, which boils down to this: The program reads a record from an input file and then uses a series of "cut" commands to break the record into parts and assign the parts to variables. There are no delimiters in the... (2 Replies)
Discussion started by: joroca
2 Replies

7. UNIX for Dummies Questions & Answers

grep and cut problem

Hello folks, I have to (e)grep out a certain pattern e.g. <TAG1> from a huge log file which does not have any space as such. The thing is that once I have 'grep'ed out the <TAG1> from the file I need to extract the content within the tags, i.e, <TAG1>Data_To_Be_Extracted</TAG1> The underlined... (9 Replies)
Discussion started by: Rajat
9 Replies

8. Programming

problem with steam buffer

Hello experts, i have one query which i am not able to solve please suggest me my problem is i have to open a filedescriptor and have to store the contents in streambuffer, i,e Code: int main () { char ch; streambuf * pbuf;size_t size; ifstream istr(const char *)fd); pbuf =... (1 Reply)
Discussion started by: vin_pll
1 Replies

9. UNIX for Dummies Questions & Answers

update my game directly from a shell

I use a wget background process to downlaod a php file on my site. Is there any way i can do this without downloading a file like updating right from the shell itself? (0 Replies)
Discussion started by: mikey1090
0 Replies
Login or Register to Ask a Question