Click here to Skip to main content
14,882,075 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how do fix and run script in linux?

if find /u01/monitor/list; then
  echo  "Path found."
elif mkdir -p /u01/monitor/list; then
  echo "Path not fount ; Path Created!"

year="date +"%y""
while [$year=="15"]
ps -e >/u01/monitor/list/Process-data.txt 
if grep 'firefox' /u01/monitor/list/Process-data.txt;then
 echo  "not found !!"
sleep 60
elif firefox;then
 echo "launch firefox"
Richard MacCutchan 27-Nov-15 6:11am
What is the question?
Albert Holguin 2-Dec-15 1:20am
What's your problem specifically? ..I see a few small issues but I don't exactly feel like setting this up and running it since you're not really asking a complete question here.

1 solution

What exactly do mean by fix and run?

However, there are some errors:

Specify the shell in the first line of the script (common are bash and sh):
## Use /bin/sh here because that is a link to the used shell

The while loop will execute never or forever depending on $year (may be not 15 initially and when it is never changed inside the loop).

The line
elif firefox;then
must be fixed. There is probably no variable firefox and there should be space between the semicolon and then.

There is a fi missing (before the done from the while)

Finally save your script with the extension .sh (EDIT: not necessary but best practice) and make it executable:
chmod 775 <script-name>
Albert Holguin 2-Dec-15 1:18am
technically speaking, the extension doesn't matter in Linux... your chmod command is out of order (filename last)... firefox is a command in this context, not a variable, this actually launches firefox if it's not running (ps command is dumping output to file, then he's attempting to check the file for an instance of firefox already running).
Jochen Arndt 2-Dec-15 3:00am
Thank you for for comment. I will fix the wrong parts. However, using an extension with shell scripts is best practice.
Albert Holguin 2-Dec-15 10:51am
Updated the vote... as to extensions with scripts, that's neither good practice or common, want an example? If you happen to have an Ubuntu installation somewhere, go to the /etc/network/if-up.d/ path... see a bunch of executables without extensions? yep, they're all bash scripts. This particular set of scripts are executed when the network manager does anything with any of the ethernet ports (they all do something relating to ethernet ports or associated services).
Albert Holguin 2-Dec-15 10:56am
...and I guess while we're at it... "#! /bin/bash" and "#! /bin/sh" are not two types of shells... actually bash is a type of shell while /bin/sh is usually a symbolic link to the system default shell (in modern Ubuntu, that's actually dash not bash... a change that was introduced back in ~2006).
Jochen Arndt 2-Dec-15 11:07am
Thank you for your replies.
sh is better because it will resolve as link to the actual shell. I will update my post again.

Overall I was a little bit lazy when writing my reply. Maybe because of the logic errors and that the missing fi should at least lead to a shell error message.
Albert Holguin 2-Dec-15 12:05pm
That's why I didn't post a solution, because the obvious errors should result in the interpreter giving you an error message that should be self-explanatory, so didn't know what they meant with "make it work" or "it doesn't work".

As to /bin/sh that should be your default way of doing things unless you're using functions that are specific to one shell or another. Ubuntu does however still have /bin/bash, so that works just as well. Think they replaced bash with dash as the default because dash is supposed to be faster and they use a lot of shell scripts during the startup process.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900