Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi
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!"
fi

year="date +"%y""
while [$year=="15"]
 do
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"
done
Posted
Comments
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):
Bash
#!/bin/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>
 
Share this answer
 
v5
Comments
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.

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