LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-16-2009, 02:46 PM   #1
DragonM15
Member
 
Registered: Sep 2003
Location: USA
Distribution: Slackware (Multiple Versions)
Posts: 455

Rep: Reputation: 31
Ash script to force-run a browser


I recently got a Nokia N810, which comes with a linux variant. I am looking to make a script that once the device is fully booted it will start the browser (conveniently named browser). The device comes preinstalled with an ash terminal.

So heres what I need:

A script written in ash that will check to see if the browser is open, if it is, then dont do anything, but if it isnt, then start it. Is there a way to make this run continuously? So if the browser is stopped it will immediately be brought back up? Unless of course the device is powering down.

Thanks
 
Old 01-16-2009, 03:45 PM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Does the device support cron for scheduling?

As far as the script is concerned...
I would use ps -ef to display all running processes
and grep br[o]wser to get just the entries that I was after
and use wc -l to count the number of entries returned.

Then it's just a case of running a test on the number of records and if -eq 0 then run browser & (in background:
Code:
#!/bin/ash
if [ $(ps -ef|grep br[o]wser|wc -l) -eq 0 ]
then
   browser &
fi
You might want to modify it a bit, but check the general process first, aditionally, you might want to run type browser from the command line to get the full path (as the PATH environment variable isn't always the same if run through cron)

Good luck.
 
Old 01-16-2009, 05:58 PM   #3
DragonM15
Member
 
Registered: Sep 2003
Location: USA
Distribution: Slackware (Multiple Versions)
Posts: 455

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by Disillusionist View Post
Does the device support cron for scheduling?

As far as the script is concerned...
I would use ps -ef to display all running processes
and grep br[o]wser to get just the entries that I was after
and use wc -l to count the number of entries returned.

Then it's just a case of running a test on the number of records and if -eq 0 then run browser & (in background:
Code:
#!/bin/ash
if [ $(ps -ef|grep br[o]wser|wc -l) -eq 0 ]
then
   browser &
fi
You might want to modify it a bit, but check the general process first, aditionally, you might want to run type browser from the command line to get the full path (as the PATH environment variable isn't always the same if run through cron)

Good luck.
I understand everything that you put into that script, except, why did you put brackets around the o in browser?

Thanks
 
Old 01-17-2009, 05:04 AM   #4
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
The brackets around the o in browser is to prevent you from needing to type grep -v grep as the grep statement doesn't meet its search criteria.

It's something I've been doing for ages
 
Old 01-17-2009, 06:19 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by Disillusionist View Post
The brackets around the o in browser is to prevent you from needing to type grep -v grep as the grep statement doesn't meet its search criteria.

It's something I've been doing for ages
...then you might be interested to know there's pgrep. Way more efficient.
 
  


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
Force Linux to run shell script in FIFO manner _hadi_ Programming 3 12-17-2006 02:12 AM
unable to run perl script using browser madhuri Debian 3 12-02-2005 04:46 PM
unable to run perl script using browser madhuri Linux - Distributions 1 11-22-2005 02:19 PM
.sh Script to run another via browser GetMooked Linux - Software 1 05-12-2005 04:41 PM
ash script (please) sourceman Linux - General 1 04-18-2002 09:38 AM

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

All times are GMT -5. The time now is 12:55 PM.

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