Calling IMacros from shell script
I have been playing around with IMacros and wanted to call macros from a shell script (as I wanted to automate port forwarding). I have been able to make this work and would like to improve it.
Hopefully others would feel the same way and would like to help me with this idea.
Its very ugly at this point but...
Here is the script that forwards ports on one of my test routers...(router code removed of course)
Code:
#!/bin/bash
imacro_code="Paste_IMacros_Code_Here"
echo "$imacro_code" | openssl enc -base64 > /tmp/tmp
sed '$!N;s/\n/ /' /tmp/tmp > /tmp/tmp1 # Yeah I know - I don't Know how to use SED properly
sed '$!N;s/\n/ /' /tmp/tmp1 > /tmp/tmp # But it works
sed '$!N;s/\n/ /' /tmp/tmp > /tmp/tmp1
sed '$!N;s/\n/ /' /tmp/tmp1 > /tmp/tmp
sed '$!N;s/\n/ /' /tmp/tmp > /tmp/tmp1
sed '$!N;s/\n/ /' /tmp/tmp1 > /tmp/tmp
sed 's/ //g' tmp > tmp1 # Removes blank spaces
code="$(cat tmp1)"
rm -rf /tmp/tmp1
rm -rf /tmp/tmp
firefox & # Firefox needs to be open already for this to work
sleep 3
firefox http://run.imacros.net/?code=$code & # Runs the IMacro code
exit 0
# If you want to try this to automate port forwarding
#
# 1. install Imacros addon (search firefox addons - its the first thing that comes up)
# 2. Go to your router login page
# 3. click record tab
# 4. click record
enter password
change port number (don't leave it the same)
click save settings
# 5. click stop recording
# 6. click the edit tab
# 7. click edit macro
# 8. copy and paste text into the quotes after $imacro_code
# 9. add variable where the IP address and ports are (optional at this point)
If someone has a method of
- only killing the Firefox windows that were opened by this script. I don't want to use killall firefox-bin and the PID for it is elusive.
- cleaning up the SED garbage or making openssl put the entire code in one line
- a better way of doing this
That would be fantastic