Help with Shell Script opening and closing a program


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Shell Script opening and closing a program
# 1  
Old 07-28-2013
Help with Shell Script opening and closing a program

REALLY new to this stuff, sorry.

So I want a shell script to open a program, wait 45 minutes, close it, and then do it all again. I want to do this because I am running an iMacros Script for a long period of time and if Firefox is not constantly restarted, memory leaks start to happen.

Anyway heres my script:

Code:
#!/bin/sh
while :
do
'/usr/lib64/iceweasel/iceweasel imacros://run/?m=macro.iim' &
sleep 5
'/usr/lib64/iceweasel/iceweasel imacros://run/?m=macro.iim' &
sleep 2700
killall firefox-bin
done

When I open it using "sh /root/whatever.sh" I get this error:
"line 12: syntax error near unexpected token 'done'"
"line 12: done"

Can anyone help? thanks!

edit: oh yeah, for anyone who isnt familiar to iMacros scripting, running the macro twice after 5 seconds is needed because firefox is not properly loaded during this time
# 2  
Old 07-28-2013
Quote:
Originally Posted by plsbbg
REALLY new to this stuff, sorry.

So I want a shell script to open a program, wait 45 minutes, close it, and then do it all again. I want to do this because I am running an iMacros Script for a long period of time and if Firefox is not constantly restarted, memory leaks start to happen.

Anyway heres my script:

Code:
#!/bin/sh
while :
do
'/usr/lib64/iceweasel/iceweasel imacros://run/?m=macro.iim' &
sleep 5
'/usr/lib64/iceweasel/iceweasel imacros://run/?m=macro.iim' &
sleep 2700
killall firefox-bin
done

When I open it using "sh /root/whatever.sh" I get this error:
"line 12: syntax error near unexpected token 'done'"
"line 12: done"

Can anyone help? thanks!

edit: oh yeah, for anyone who isnt familiar to iMacros scripting, running the macro twice after 5 seconds is needed because firefox is not properly loaded during this time
If you're saying that it takes firefox 5 seconds to load before you can run your iMacros script; why not start firefox, sleep 5 seconds, and then launch your iMacros script instead of starting the script twice when you know the first one will fail and maybe leave firefox in an "unknown" state.

The error messages you're getting are from line 12 in some script that isn't identifying itself. Since there are only 9 lines in the shell script you're showing us, this script isn't producing the error. Could the error message be coming from the iMacros script that is failing to start properly?

Rather than killing firefox, it would be much better to debug your iMacros script to stop leaking memory.

What do you see if you run the command:
Code:
'/usr/lib64/iceweasel/iceweasel imacros://run/?m=macro.iim'

at a time when firefox is not running?

What do you see if you run the same command when firefox is running?

What does your iMacros script look like?
# 3  
Old 07-28-2013
Quote:
If you're saying that it takes firefox 5 seconds to load before you can run your iMacros script; why not start firefox, sleep 5 seconds, and then launch your iMacros script instead of starting the script twice when you know the first one will fail and maybe leave firefox in an "unknown" state.
I could do that, it would be the same thing though.

Quote:
The error messages you're getting are from line 12 in some script that isn't identifying itself. Since there are only 9 lines in the shell script you're showing us, this script isn't producing the error. Could the error message be coming from the iMacros script that is failing to start properly?
Oh sorry, the script is actually 12 lines, I had 3 lines for comments and I just removed them when I posted it here.

Quote:
Rather than killing firefox, it would be much better to debug your iMacros script to stop leaking memory.
The problem is Flash, as my script macros a Flash website, and therefore it must restart once in a while. I've coded a simple batch file on Windows that does this, however I want to do the same on Debian.

Quote:
What do you see if you run the command:
Code:
'/usr/lib64/iceweasel/iceweasel imacros://run/?m=macro.iim'

at a time when firefox is not running?

What do you see if you run the same command when firefox is running?

What does your iMacros script look like?
Firefox opens, but my script doesn't. Which is why I need to run the command twice, as explained here: wiki.imacros.net/iMacros_for_Firefox#Command_Line_Support

Thanks
# 4  
Old 07-28-2013
Going to the web page you posted, there is absolutely nothing that looks like what you're doing. The following suggestions are there:
Quote:
Command Line Support

You can start imacros (or Javascript scripts) inside of Firefox via the command line:

Code:
 "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"  imacros://run/?m=...

or
Code:
 "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"  imacros://run/?code=...

for instance:

Code:
 "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"  imacros://run/?m=Demo-FillForm.iim

Note: When you first start Firefox via the command line the iMacros extension is not immediately active . It takes a few seconds for Firefox to activate it. So the imacros://run/ command does get intercepted already but not yet processed by iMacros and a blank page appears.

Solution: Make sure that Firefox is already running. If you start Firefox a second time, Firefox will direct this new command automatically to the already running instance. Now iMacros can "see" the imacros://run/ URL and start the macro.

You can use a batch file like this:

Code:
 start /B "C:\Program Files\Mozilla Firefox\firefox.exe"  http://www.google.com
 ping 127.1.1.1 (or pause or sleep ... it is just to cause a small delay)
 start /B "C:\Program Files\Mozilla Firefox\firefox.exe"   imacros://run/?m=Demo-FillForm.iim

Note: If you use the batch start command, Firefox must be the default browser.

More information: Our users created several useful forum posts about the command line feature:

Automating task each day
Problem with starting imacros
Starting a script from DOS cmd line?
Batch File: Load Firefox, Run Macro(s), Close
Schedule macros with the "My Weekly Browsing Schedule" add-on (slides 30-31)
Alternative solution: If you need more control over Firefox you can use the iMacros Scripting Interface that comes with the iMacros Enterprise Edition. This method gives you complete control over Firefox and Internet Explorer. For example, you can return error codes or extracted data from the browser to your program or script.

For Mac OS X users: to start a macro from the OS X command line or as a scheduled job, you can use the following command syntax (Thanks to Christopher A. for this hint):
Code:
/usr/bin/open /Applications/Firefox.app "imacros://run/?m=Demo-FillForm.iim"

What operating system are you running? The comment I marked above in red seems to directly address your issue. The code I marked in blue is their suggestion for how to handle the issue on Windows (which looks exactly like what I suggested), and the code I marked in green is their suggestion for how to handle the issue on Mac OS X.

What operating system are you using? What is your "default" browser? What type of shell is /bin/sh on your system (an old Bourne shell as on Solaris 10 systems, a Korn shell as on many other UNIX systems, a bash shell as on many Linux systems, or something else)?

Do you have iMacros Enterprise Edition?

Note that showing us your MODIFIED script and the errors produced by your unmodified script makes it harder for you to get help. Having us look at error messages that don't match your code makes it impossible for us to diagnose your problem and makes us wonder if we can trust anything you show us.
# 5  
Old 07-29-2013
Quote:
Originally Posted by Don Cragun

What operating system are you running? The comment I marked above in red seems to directly address your issue. The code I marked in blue is their suggestion for how to handle the issue on Windows (which looks exactly like what I suggested), and the code I marked in green is their suggestion for how to handle the issue on Mac OS X.

What operating system are you using? What is your "default" browser? What type of shell is /bin/sh on your system (an old Bourne shell as on Solaris 10 systems, a Korn shell as on many other UNIX systems, a bash shell as on many Linux systems, or something else)?

Do you have iMacros Enterprise Edition?

Note that showing us your MODIFIED script and the errors produced by your unmodified script makes it harder for you to get help. Having us look at error messages that don't match your code makes it impossible for us to diagnose your problem and makes us wonder if we can trust anything you show us.
I'm running Debian. And yes, I did what the website said to do on Windows. Those are commands for batch files. I'm running Debian, not Windows.
Don't know what /bin/sh is on the system.

I'm running Firefox. I'm not using the enterprise edition. The script isn't modified, I just removed some comments at the top
# 6  
Old 07-29-2013
Quote:
Originally Posted by plsbbg
I'm running Debian. And yes, I did what the website said to do on Windows. Those are commands for batch files. I'm running Debian, not Windows.
Don't know what /bin/sh is on the system.

I'm running Firefox. I'm not using the enterprise edition. The script isn't modified, I just removed some comments at the top
The syntax is different between UNIX and Linux shell scripts and Windows batch scripts, but the commands that need to be run to bring up your iMacros script in a Firefox window should be very similar.

The examples shown on the web page you referenced all invoke a browser and give it an operand that is a relative pathname to an iMacros script. Your shell script does not invoke a browser; it just invokes your iMacros script (with no operands or options) as if it were a standalone command. There is absolutely no indication on the web page you referred to that the command line you're using should work. It may well do what you want, but there is nothing on the web page you referenced that would explain why it should.

I'm sorry that you don't realize that deleting three lines from a shell script is modifying that script. There is nothing obviously wrong in the 9 lines you showed us, but the syntax error on line 12 clearly tells us that something in the 3 lines you didn't show us are causing a syntax error in the 9 lines you showed us (or you changed something else in the 9 lines you showed us).

Since you refuse to show us the code that seems to be causing your problem, I don't see how we can help.
# 7  
Old 07-29-2013
Fixed it, I just had to remove the & symbol...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script Works But Need It to Exit Upon Closing Program

Running Xubuntu 16.04 with shell version "GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)," I have a working script that consistently renames a Chrome window: #!/bin/sh while sleep 1; do xdotool search --name chrome 2>/dev/null | while read id; do xdotool set_window --name... (21 Replies)
Discussion started by: jakefish
21 Replies

2. Shell Programming and Scripting

Print a closing XML tag shell script

I have a shell script that does everything I need it to do. But, when I was testing it I realized it doesn't print the closing XML tag.... Does anyone know how to incorporate printing the XML tag with my script? I am using AWK any help would be appreciated. (4 Replies)
Discussion started by: risarose87
4 Replies

3. Shell Programming and Scripting

Opening Child Shell & Executing a script in the same context

Hi, Is the below possible (SHELL = tcsh)? -- I want to write an 'alias' something like this - alias set_my_work "setenv SOME_VAR;tcsh -i;source work_script.cshrc" The intention is to run this alias and enter a child shell, at the same time ensuring that the work_script.cshrc is source-ed.... (0 Replies)
Discussion started by: mishra.a.c
0 Replies

4. Shell Programming and Scripting

Help with opening another file from within a shell script

Hi, I am trying to open a file that I have created from withn a shell script and cannot seem to get it working. Does anyone have any ideas? Thanks. (2 Replies)
Discussion started by: tdsrogers
2 Replies

5. OS X (Apple)

Opening and Closing Shares via ssh

Might anyone have an idea on how to mount an xserve share via ssh, then close the share connection? (3 Replies)
Discussion started by: unimachead
3 Replies

6. Shell Programming and Scripting

Finding opening and closing braces

I am reading a cpp file thru shell script . There are many fuctions inside the cpp file eg pvvd_fncn_name1 { ..... something } pvvd_fncn_name2 { ..... something } what I require is a method to find the first opening brace and the coresponding last brace and search... (2 Replies)
Discussion started by: ultimatix
2 Replies

7. Shell Programming and Scripting

closing a telnet session on error, in a shell script

I am using a shell script to telnet into a remote unix server and execute certain commands. But if any command being executed remotely, throws an error, the script just hangs. And the telnet session does not get closed. I want to be able to close the session and complete the script execution in... (1 Reply)
Discussion started by: farahzaiba
1 Replies

8. Shell Programming and Scripting

Getting Following problem when opening shell script (Very Urgent)

Hi All, Actually when i am trying to open my shell script file 1.sh then i am getting the following error. > vi 1.sh "/var/tmp/ExdNaarK" No space left on device Can anybody tell me that how to rectify it. It is very urgent. Because i am not able to do any work due to the above error. ... (1 Reply)
Discussion started by: sunitachoudhury
1 Replies

9. Post Here to Contact Site Administrators and Moderators

Opening and closing threads

Hi all, Just thought I'd mention something I've noticed since joining this forum :) Would it be a good idea to close threads once the initial question that was posted has been answered? I notice a few posts where people go on and on and as soon as you post a reply to one question they... (2 Replies)
Discussion started by: _Spare_Ribs_
2 Replies

10. Post Here to Contact Site Administrators and Moderators

Requests for Opening/Closing Threads

Please send an email to the administrator(s) of the board with thead ID and forum for any thread that is closed that you want open (or open that you want closed). All requested considered. Our apologies if sometimes threads are closed early. If this happens, please email :) Nobody is perfect... (0 Replies)
Discussion started by: Neo
0 Replies
Login or Register to Ask a Question