Register
It is currently Wed Dec 13, 2017 12:39 pm

Help simple bash


All times are UTC - 6 hours


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 PostPosted: Sat Apr 30, 2016 7:54 pm   

Joined: Sat Apr 30, 2016 7:26 pm
Posts: 10
Dear , I am newbie and want to make a bash to perform the following tasks:
1) go to the directory /home/chatizpano/radio
2) run this ./sc_serv rhiz.conf
3) ^ Z (control Z to pause the program)
4) bg ( background execution )
5 ) ^ ad (control A, D closed session)

So I do ssh :
Quote:
[[email protected] ~]$ cd /home/chathizpano/radio
[[email protected] radio]$ ./sc_serv rhiz.conf
*******************************************************************************
** SHOUTcast Distributed Network Audio Server
** Copyright (C) 1998-2004 Nullsoft, Inc. All Rights Reserved.
** Use "sc_serv filename.ini" to specify an ini file.
*******************************************************************************
^Z5/01/[email protected]:40:07> [sleeping] 0 listeners (0 unique)
[1]+ Detenido ./sc_serv rhiz.conf
Then Control key A, D , but here the screen is closed so I can not copy it.


I tried and saved as shoutcast.sh:
Code:
#!/bin/bash
cd /home/chathizpano/radio
./sc_serv rhiz.conf
^Z
bg
^ad
exit


Error:-bash: ./shoutcast.sh: /bin/bash^M: intérprete erróneo: No existe el fichero o el directorio

I apologize for my bad English , I only speak Spanish.


Top
 Profile  
 PostPosted: Sun May 01, 2016 5:53 am   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 560
Please explain what you are trying to achieve
and post the script sc_srv


Top
 Profile  
 PostPosted: Sun May 01, 2016 6:55 pm   

Joined: Sat Apr 30, 2016 7:26 pm
Posts: 10
uhelp wrote:
Please explain what you are trying to achieve
and post the script sc_srv

sc_srv script is known shoutcast server to broadcast radio and the rhiz.conf ( sc_serv.conf ) is the configuration file containing the IP, port and other data needed to operate.
What I need is that the script remains working in the background using a bash file that I simplify the task, leaving added to a cron on my VPS .
I want to know how to be represented in language bash: Control Z (^ z ) and background (bg ) because the syntax is wrong.
The steps you need to follow the script are as indicated above.

What should I add the script is to check if the ./sc_serv rhiz.conf process is running on my VPS and otherwise to make the process run in the background, so I do not need to have open Linux console.

The way I do it manually, you invoke the script with your configuration file in the foreground , then stop with Control Z (^ z ) , then leave it in the background with bg , which to finish my press Control A, D (^ad) , not to depends on my console.

I did and run, the error that gave was that the file format for Unix was not because I did it in an editor, which did not generate that format.

What remains to me, it is to add a conditional to check if the process is running on the VPS and check the syntax of the Control keys.

I hope that with this information, it may be possible to help me make the script.

Using Linux Centos 7 64bit .
Thank you. :)


Top
 Profile  
 PostPosted: Mon May 02, 2016 11:55 am   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 560
First of all i recommend that you gain basic knowlegde of Linux before trying to run a server.

The shoutcast software is available as a native Linux software.
In the Linux jargon we call a server process a daemon

So the common way to start a shoutcast server is a simple command:
Code:
./sc_serv daemon /path/to/your/shoutcast.conf

There is NO need to write a shellscript for starting a server instance.

It is a good thing to read docs BEFORE you try to run server software.
Read about shoutcast http://wiki.shoutcast.com/wiki/SHOUTcast_DNAS_Server_2

A linux guy is dedicated to open source.
Shoutcast is not.
You might want to consider using http://www.icecast.org/ instead.

If you want to run a command within background just add an ampersand at the end of the commandline.
Code:
#!/bin/bash

# next command runs in background
someCommand &
# the shell runs the line above and returns immediately

# to run the next command

nohup AnotherCommand
# "nohup" is short for "no hang up" and refers to the ancient times,
# where the telephon line transmitted the commands to "real terminals"
# Prefixing any command with "nohup" and tells the terminal not to stop its run
# even if one "hangs up".  This is one way to run a command independently
# from any terminal (aka shell) connections.


And some clarifications on the shortcuts.
<ctrl><z> says STOP running this command. The process running this command is not destroyed but it sleeps endless until is brought into foreground again. This is DEFINITELY NOT what you want.
There are some more methods to run a command in background.
Read about with these commands:
Code:
man nohup
man disown
help disown
help jobs
man fg
help fg
man bg
help bg

Note: help gives help for internal bash commands aka. builtins.
manual is the command for reading manpages for nearly every external command (binaries found usually in /bin /sbin etc.)

There is also a command called info
Complex commands often come with info pages.
info uses a kind of hyperlink system.
Read man info

And use the short help most commands provide:
Code:
someCommand --help
someCommand -h
someCommand -?
(Not every command implements all of this. But --help is a good bet.

And in general learn about redirections.
Redirecting is a widely used and very important technique within Linux.

<ctrl><a> is short for "go to begin of line"
There is no <ctrl><a> <d> within the bash. This would just insert a "d" at the beginning of line.
I think that you do mean this shortcut for screen
screen is a terminal multiplexer. It is commonly used to let long running processes stay connected with the terminal no matter whether the ssl - connection breaks or the user disconnects.
Within screen <ctrl><a> is the meta key for screen telling screen that the next keystroke(s) are a meant to be a command for screen itself, not for the bash running. And the screen command <d> means "dettach from this screen session". Then the screen session and all its "windows" (i.e. all the shell instances with the commands running inside) just keeps running without a user attached to it.


Top
 Profile  
 PostPosted: Tue May 03, 2016 2:28 am   

Joined: Sat Apr 30, 2016 7:26 pm
Posts: 10
Very grateful uhelp for the clear and comprehensive information.

I did it! =))
Code:
#!/bin/sh
PROCESS='sc_serv'
if ps ax | grep -v grep | grep $PROCESS > /dev/null
then
echo "$PROCESS is running"
else
echo "Oops! $PROCESS is not working"
cd /home/juan/radio
screen -s -d -m
nohup ./sc_serv rhiz.conf -ah / > ./salida.txt 2> /dev/null &
fi


Top
 Profile  
 PostPosted: Tue May 03, 2016 7:01 am   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 560
There is no need to start the screen.
This instance of screen runs without doing anything.
And the server started with nohup in next line does NOT run within screen.

If you want to run this command within screen, you must use screens config file .screenrc and put a line like this into:
Code:
screen -t "my shoutcast"  0  /path/tp/sc_serv /path/to/rhiz.conf
This sets the -title of ascreen-window number 0 to my shoutcast and runs your server.

In your script screen does absolutely nothing.
Delete this line.


Top
 Profile  
 PostPosted: Thu May 05, 2016 9:22 pm   

Joined: Sat Apr 30, 2016 7:26 pm
Posts: 10
Ok uhelp, thank you!! =))


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP