LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 03-05-2020, 07:09 AM   #1
anon130
LQ Newbie
 
Registered: Feb 2020
Posts: 4

Rep: Reputation: Disabled
[NEWBIE] Help with Bashscript for Google Cloud VM instance.


//Startup Script
#! /bin/bash
yum -y update

su csgoserver -c "./csgoserver update"
su csgoserver -c "./csgoserver start"


//Shutdown Script
#! /bin/bash

su csgoserver -c "./csgoserver stop"


Is there a way for me to cd into "/home/csgoserver" at the beginning so i can get this script to work. Thanks. Im not entirely sure about this script
 
Old 03-05-2020, 07:16 AM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
yeah add "cd /home/csgoserver" in your script where you need to go into that dir without the quotes then see what that does for you. then if no, then go into trouble shooting mode to find out why it doesn't then came back and let the others try to help you figure it out if you cannot.

(I'll let someone else tell you about code blocks)

Last edited by BW-userx; 03-05-2020 at 07:18 AM.
 
Old 03-05-2020, 07:20 AM   #3
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555
Firstly, wrapping [code] tags around your scripts makes the post easier to read. (That's the # icon on the toolbar.)

Quote:
Originally Posted by skye7777 View Post
Is there a way for me to cd into "/home/csgoserver" at the beginning so i can get this script to work.
Yes, you can do exactly that - put cd /home/csgoserver at the beginning, and separate it from the following command(s) with either a ";" or with "&&" if you only want the second command to execute when the first command succeeds.

Alternatively, you can specify the --login option - as per the su man page one of the four things this does is "changes to the target user's home directory".

 
Old 03-05-2020, 07:42 AM   #4
anon130
LQ Newbie
 
Registered: Feb 2020
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by BW-userx View Post
yeah add "cd /home/csgoserver" in your script where you need to go into that dir without the quotes then see what that does for you. then if no, then go into trouble shooting mode to find out why it doesn't then came back and let the others try to help you figure it out if you cannot.

(I'll let someone else tell you about code blocks)
Im sorry about not following rules. Im familiar with normal linux commands, is it possible to type linux commands directly into bash?
 
Old 03-05-2020, 08:02 AM   #5
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by skye7777 View Post
Im sorry about not following rules. Im familiar with normal linux commands, is it possible to type linux commands directly into bash?
that is the moto. if you can do it on the command line then you can do it in the script. that is a good thing, because all you need to do is open a terminal work out the commands then add them into your script. then of course still do test runs before production.
 
  


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
LXer: Cloud 5: Dispelling cloud myths, the cloud security excuse, and the fight for cloud supremacy LXer Syndicated Linux News 0 06-20-2014 04:12 PM
LXer: Cloud 5: NSA not killing cloud, cloud IT jobs, rise of cloud brokers LXer Syndicated Linux News 0 03-02-2014 09:51 AM
LXer: Cloud 5: Netflix's cloud-connected brain, 5 cloud myths and from cloud to fog LXer Syndicated Linux News 0 02-21-2014 02:20 PM
LXer: It's a cloud, cloud, cloud, cloud world LXer Syndicated Linux News 0 07-23-2013 05:40 PM

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

All times are GMT -5. The time now is 01:41 AM.

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