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 02-01-2018, 08:48 AM   #16
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 345

Original Poster
Rep: Reputation: Disabled

Code to work with the sample code i wrote 8 messages ago.

Code:
#!/bin/bash
path=$(pwd)
sname=$0

trap ctrl_c INT
function ctrl_c() {
if [[ -f "$path/pid.tmp" ]]
then	
pid=$(sed -n 1p < "$path/pid.tmp")
rpid=$(ps -p "$pid" -o pid= | awk '{print$1}')
if [[ "$rpid" == "$pid" ]]
then
kill $pid >/dev/null 2>&1
exit 1
else
exit 1
fi	
else
exit 1
fi
}
if [[ ! -f $path/null ]]
then
echo "0" > $path/null
exec $sname 2>/dev/null
exit 1
fi
rm -rf $path/null >/dev/null 2>&1
srvnmb=$(wc -l "$path/1" | awk '{print$1}')
rm -rf "$path/stream*" >/dev/null 2>&1
rm -rf "$path/pid.tmp" >/dev/null 2>&1
for i in $(seq "$srvnmb")
do
chkf=$(sed -n "${i}p" < "$path/1")
chkurl=$(echo "$chkf" | head -c 4)
case "$chkurl" in
http|rtmp|HTTP)
wget -q "$chkf" -O "$path/stream" & echo $! > "$path/pid.tmp" 
pid=$(sed -n 1p < "$path/pid.tmp")
sleep 4 
rpid=$(ps -p "$pid" -o pid= | awk '{print$1}')
if [[ "$rpid" == "$pid" ]]
then
kill $pid >/dev/null 2>&1
fi
if [[ ! -f "$path/stream" ]]
then
echo "Error reading captured file"
else
stsz=$(wc -c "$path/stream" | awk '{print$1}')
if [[ "$stsz" -le "100" ]]
then
echo "$chkf is down"
else
echo "$chkf is ok"
fi
fi
;;
*)
;;
esac
rm -rf "$path/stream" >/dev/null 2>&1
rm -rf "$path/pid.tmp" >/dev/null 2>&1
done
 
Old 02-01-2018, 09:30 AM   #17
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
You don't like indentation in code style?
 
Old 02-01-2018, 09:49 AM   #18
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
it does make it hard to read, knowing what does what.. being like that... maybe has no thumbs to hit space bar... just saying..
 
Old 02-01-2018, 12:22 PM   #19
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 345

Original Poster
Rep: Reputation: Disabled
lol , well , if you are open the code file with geany then it will look fine

what matters is that it is working as i expected .
I may have other difficulties ahead , but that is for another thread .
 
Old 02-01-2018, 01:27 PM   #20
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 pedropt View Post
lol , well , if you are open the code file with geany then it will look fine

what matters is that it is working as i expected .
I may have other difficulties ahead , but that is for another thread .
Like growing ? lmao j/k
 
  


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
Unable to kill process with kill -9 pgb205 Linux - Software 5 01-13-2011 03:55 PM
Unable to identify tty name error on new install fbsduser Slackware 4 10-04-2010 09:34 PM
Unable to mount loop filesystem error with PCLinuxOS Pr9.1 sc123 Linux - Software 1 09-19-2008 11:08 AM
one line identify and kill PID (scriptable) r00tb33r Linux - Software 3 02-06-2008 04:52 PM
Webmin error - unable to identify operating system LittleAngel Linux - Software 2 05-15-2004 04:21 PM

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

All times are GMT -5. The time now is 01:36 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