Answer» I have been using Linux for a few MONTHS now and can get AROUND fairly well but I am still new to the different languages out there for linux. I am currently using Ubuntu 7.10 and am in need some some scripting help. I am trying to convert a VB script to python or perl. The only main reason i am trying to convert it to one of these languages particularly is because I am trying to learn them. This way it is a learning experience and helpful one. But I have my script SHOWN below. Is there a way to convert these real easy or is someone proficient enough to help me convert this over?
On Error Resume Next '##################### 'Wait a short time to allow the process to start, assuming it's an auto-launch process. 'Monitor for the process existing. 'If the Process exists, continue to monitor; waiting 2 seconds between each check ' If you don't put a 'wait' in there, it'll hog 100% of the CPU just to monitor. 'If the Process does not exist, exit the monitoring process, and logoff the user '##############################
Set sho = Wscript.CreateObject("Wscript.Shell") strComputer = "." strProcess = "iexplore.exe"
i=0
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set objShell = CreateObject("Wscript.Shell")
'wscript.sleep 36000 'wait several seconds before starting this script to allow process time to launch
Do while i=0 wscript.sleep 1200 '1=1ms, so 600=1 second
Set colProcesses = objWMIService.ExecQuery _ ("Select * from Win32_Process Where Name = '" & strProcess & "'")
If colProcesses.Count = 0 then sho.LogEvent 4, "REMOTE Session Terminated" i=1 Else 'Do Nothing, it's a running process End If Loop
sho.run "shutdown -l",0,False 'This time it's FALSE because we want the script to exit regardless of the logoff. wscript.quit you should learn the basics first before trying to do things like this. You can start with Python, as its very easy to learn and the syntax is very easy to read. Start by going to Python doc site. Take the tutorial, learn the reference libraries...etc...get a good Python book also and learn by practicing. by the end of it, you should be able to convert that vbscript to Python. Thank you for the link I am most definitely going to go through the tutorials but unfortunately this is something I need help with a bit sooner than what my learning abilities are going to allow. On a more normal basis I like to have at least a basic knowledge of what I am working with to help but unfortunately this time I don't have time.
Any help would be great.Ok I have found after much reading and frustration that I have been making things harder than what they need to be. I have learned that BASH is much like DOS and i like dos so I have been working with that and have came up with the script below but when firefox is not open it doesn't shut down. Any thoughts?
Thanks,
SCRIPT:
if [ 'pidof firefox-bin' ] then sleep 15 else shutdown -f fi
short and sweet. shutdown is used for shutting down the system. If you just want to "close" firefox, issue kill command against the pid of firefox. the shell is much like DOS, and better.
|