LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-18-2017, 12:30 PM   #16
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 292

Original Poster
Rep: Reputation: Disabled

i want to test gnome terminal because msfconsole get errors with xterm .
 
Old 03-18-2017, 12:37 PM   #17
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,241

Rep: Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453
what kind of error is it? can you show us some details?
 
Old 03-18-2017, 01:38 PM   #18
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 16,897
Blog Entries: 10

Rep: Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026
i had a look at a virtual machine with centos 6.x, which has an old version of gnome-terminal, and it is as i said:
starting a gnome-terminal, it goes to background immediately.
that old version does not have an option to explicitely start it in foreground, but maybe yours has?
try
Code:
man gnome-terminal
gnome-terminal -h
and see which command line option you could add.
 
Old 03-18-2017, 02:22 PM   #19
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,149

Rep: Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523
It's hard to believe, but gnome-terminal uses some client-server architecture, involving DBUS. I suggest using xterm, rxvt or other sane terminal-emulator.
 
Old 03-18-2017, 05:08 PM   #20
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 292

Original Poster
Rep: Reputation: Disabled
Quote:
what kind of error is it? can you show us some details?
The error is that if i run rc script independently from main script , then everything works fine , but if i start the rc script from another script then msfconsole pops up an error .

However , my logic was working in the code , but i had to fix some stuff in the code to put it work .


Quote:
function outf(){
out=out.tmp
sleep=$((sleep + 1))
if [ $sleep -eq "10" ] then
echo "timeout - was not possible to get msfconsole output"
exit 1
fi

if [ -f $out ]; then
echo "Continuing the script"
else
echo "waiting for output from msfconsole"
sleep 2
outf
fi
}
bla
bla
bla
gnome-terminal -e "msfconsole -r test.rc > out.tmp"
sleep="1"
outf
cat out.tmp
After testing the launch with gnome . i also got the same error that i had with xterm .
I think that the possible cause was that in rc script to msfconsole i used an "exit -y" at the end , so the msfconsole could close and xterm close that window .

Anyway , it is solved this issue .
 
Old 03-23-2017, 09:13 AM   #21
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 698

Rep: Reputation: 110Reputation: 110
gnome terminal daemonizes, hence you cannot wait with out of the box solutions. Ajusting sleeps... meh

Code:
gnome-terminal -e "msfconsole -r test.rc > out.tmp" 
waitpid=$!

isrunning=$(kill -0 ${waitpid})

while ${isrunning}
do
  isrunning=$(kill -0 ${waitpid}
  sleep .1
done

cat out.tmp
This will wait till the process is done; so it will keep waiting until gnome-terminal exits; however, regardless of the return status of "msfconsole" cat will run; there is no error checking.
 
Old 03-23-2017, 09:26 AM   #22
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,241

Rep: Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453
the proper way is (at least I think) to get the pid of msfconsole and wait for it. something like this:
Code:
#pseudo-code
gnome-terminal -e "msfconsole -r test.rc > out.tmp" 
PID=$(pgrep msfconsole)
wait -p $PID
cat out.tmp
not tested
 
1 members found this post helpful.
Old 03-23-2017, 10:10 AM   #23
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,590

Rep: Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908
Quote:
Originally Posted by pan64 View Post
the proper way is (at least I think) to get the pid of msfconsole and wait for it.
AFAIK, you can only wait for child processes, so this can't work.
 
Old 03-23-2017, 11:59 AM   #24
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,241

Rep: Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453Reputation: 5453
Quote:
Originally Posted by ntubski View Post
AFAIK, you can only wait for child processes, so this can't work.
in that case you can create a lock file and do something like this:
Code:
gnome-terminal -e flock -x /tmp/lockfile "msfconsole -r test.rc > out.tmp"
flock -s /tmp/lockfile echo done
cat out.tmp
not tested again
 
Old 03-23-2017, 04:19 PM   #25
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 292

Original Poster
Rep: Reputation: Disabled
You don`t need to do it like that because something wrong may happen in msfconsole and gnome will be stuck , in that case your script will not go further because it is waiting for lockfile to be released witch will be not in case msfconsole gets an error .

Best way to do it is like i told in my previous post , create a function to search for output of msfconsole , and at same time define a timeset for operation in gnome to be completed .
If gnome closes before the time limit then script will continue , if gnome gets stuck in the middle of the process then timeout will popup and script will continue with an error message ahead saying that "File not found" or whatever .
 
  


Reply

Tags
bash, command, gnome terminal, wait


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Wait for “git clone” to finish in bash luftwaffe Linux - Software 3 05-25-2016 11:18 AM
Wait for a remote script to finish before executing another vikas027 Programming 4 08-07-2012 01:48 AM
How to create a bash script to wait for wget to finish and then continue danlee Linux - General 14 05-30-2008 11:21 AM
bash-script won't wait for application to finish TLV Linux - Software 24 09-30-2004 11:18 PM
Pppd does not wait for chat script to finish ruchika Programming 1 08-28-2003 11:30 PM

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

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