Kamis, 02 Desember 2010

How to safe restart firefox in Linux

Hi guys:

How to restart firefox? all old session can be restored.
I am writing one script to install my plugin to firefox, right now I failed to restore old sessions.

Here is my code, any comments or suggestion are appreciated.
 
RestartBrowser()
{
bin="firefox"
PID_LIST=$(ps -ef |grep $bin |grep -v "grep" |awk '{print $2}')
local result=$?
local PID_NUM=0

local restart=0
for pid in $PID_LIST
do
if [ $PID_NUM -eq 0 ]
then
echo "Restart Firefox to complete your change"
echo "Press Enter key to restart firefox, any other key to quit"
key=""
read -s -n 1 key
X="X"
if [ X$key !="X" ]
then
restart=$FALSE
echo "Cancel restart firefox"
break
else
restart=$TRUE
fi
fi
kill -9 $pid
result=$?
if [ $result -ne 0 ]
then
echo $(date) ":" "Failed to kill firefox pid:$pid"
fi
sleep 3
#restart web browser
export DISPLAY=":0.0"
firefox &
result=$?
PID_NUM=$[ $PID_NUM + 1 ]
echo $(date) ":" "Restart firefox $pid"
done
if [ $PID_NUM -eq 0 ]
then
result=0
echo $(date) ":" "No firefox has been restarted"
fi
echo $(date) ":" "Enter RestartBrowser firefox restart:$restart, result:$result"
return $result
}

Tidak ada komentar:

Posting Komentar