OK for a while now I have been running my server in Windows Server 2008, well I finally changed it over to Ubuntu Desktop. My problem is that I have several batch scripts that have to be converted over... The problem I that I have no idea how to convert them so I looked it up, and upon doing so, I found that there is no GoTo function in SHELL, and almost all my batch scripts use a go to functions. I have converted one of my scripts the best I can, but I can't get it to work, so can someone please look at the code and tell me what I have done wrong converting it?
Code:
- #! /bin/ksh
- tasklist /FI "IMAGENAME eq Server.exe" 2> /dev/null | find /I /N "Server.exe"> /dev/null
- if [ $? = 1 ]
- then
- echo "<FONT COLOR=#00DD00><B>ONLINE</B></FONT>" > status.txt
- else
- echo "<FONT COLOR=#DD0000><B>OFFLINE</B></FONT>" > status.txt
- fi
I have no idea how tasklist works in SHELL, but the ERRORLEVEL ($1) function isn't even working.
Edit: If the codes isn't clear enough, i want the file to check to see if the server.exe is running. If it is it will say the "then" option, and if it isn't, then it will say the "else" option. Before when I did this code I used goto and if and if not with the error level functions:
Code:
- tasklist /FI "IMAGENAME eq Server.exe" 2>NUL | find /I /N "Server.exe"> NUL
- IF ERRORLEVEL 1 goto Process_NotFound
- IF NOT ERRORLEVEL 1 goto Process_Found
- :Process_Found
- echo "<FONT COLOR=#00DD00><B>ONLINE</B></FONT>" > status.txt
- goto END
- :Process_NotFound
- echo "<FONT COLOR=#DD0000><B>OFFLINE</B></FONT>" > status.txt
- goto END
- :END
This is a snippet of a script I run to check if apache2 is running. Not sure what the differences would be with Ubuntu desktop.
Code:
- #!/bin/bash
- a=$(ps cax | grep -c ' apache2$')
- if [ $a -ge 1 ]; then
- echo "Apache is Running :)";
- else
- echo "Apache is NOT running"
- fi
ok so in general, would iot be posisble that something like this would work?
Code:
- #!/bin/sh
- if ps ax | grep -v grep | grep Server.exe > /dev/null
- then
- echo "<FONT COLOR=#00DD00><B>ONLINE</B></FONT>" > status.txt
- else
- echo "<FONT COLOR=#DD0000><B>OFFLINE</B></FONT>" > status.txt
- fi
I got the coding example from here: http://www.anyexample.com/linux_bsd/bash/check_if_program_is _running_with_bash_shell_scrip t.xml
Edit: OK some what related question, I know when using the terminal to set a cronjon you use crontab -e to bring up the text menu to submit the cronjob. I currently have 5 **** /Path/To/status.sh but for some reason its not working. I want it to run the script every 5 minutes, so based on the docs I have found it should be right![]()
That cron would tell it to run at 5 past the hour. You'd want:
*/5 * * * * /path/to/status.sh
Or you may need:
*/5 * * * * /path/to/bash /path/to/status.sh
As for the code, it's only a snippet I got from somewhere. My shell skills leave much to be desired. have you tried:
Code:
- #!/bin/bash
- a=$(ps cax | grep -c ' Server.exe$')
- if [ $a -ge 1 ]; then
- echo "<FONT COLOR=#00DD00><B>ONLINE</B></FONT>" > status.txt
- else
- echo "<FONT COLOR=#DD0000><B>OFFLINE</B></FONT>" > status.txt
- fi
hmm the crontab still wont work![]()
also I got the script to now output the text file, the i dont currently have the server program on my pc, so i used apache2 to test and it worked.
hmm the crontab still wont work![]()
also I got the script to now output the text file, the i dont currently have the server program on my pc, so i used apache2 to test and it worked.
Can you run /bin/bash /path/to/status.sh via the command line?
yea I can, thats how I know it works, but when i set it as a crontab, well it wont process.
Side question, you mentioned using apache2, and i was wondering if you could possible give me an idea how to set it up rightI can only access the site from within my local network, though when trying to go outside the network it say the site dont exist. I have been following multiple guides and so far i've only been making things worse XD
yea I can, thats how I know it works, but when i set it as a crontab, well it wont process.
Side question, you mentioned using apache2, and i was wondering if you could possible give me an idea how to set it up rightI can only access the site from within my local network, though when trying to go outside the network it say the site dont exist. I have been following multiple guides and so far i've only been making things worse XD
Are you using a router on your network? You will need to change the settings on it to forward port 80 to your machine.
It's also possible that the connection is getting blocked by your firewall.
trust me, that is not the problem
i have DMZ setup and router to my server. Network wise, nothing has changed since I was running Win Server 2008, though maybe its a firewall within the system? I'm not sure how linux works or anything like that so I have no idea if it has its own internal firewall.