Difference between revisions of "Making a handy amulecmd script"

From AMule Project FAQ
Jump to: navigation, search
 
Line 69: Line 69:
 
== How to use these scripts ==
 
== How to use these scripts ==
  
Simply save them to a plain text file and make them executable by applying 'chmod u+x <yourscriptfilehere>'. This will work on most OS'es, except maybe for Windows since the standard version does not come with command line tools like grep.
+
Simply save them to a plain text file and make them executable (f.e., on linux by applying 'chmod u+x <yourscriptfilehere>'). This will work on most OS'es, except maybe for Windows since the standard version does not come with a useful command line shell.
  
 
== Conclusion ==
 
== Conclusion ==
  
 
There are a hunderd different things you can do with the output of "show log", only limited by your imagination ;) If you want to change the behaviour of the script you might want to check out commands such as grep (easy), awk (a bit harder) and sed (can be quite tricky).
 
There are a hunderd different things you can do with the output of "show log", only limited by your imagination ;) If you want to change the behaviour of the script you might want to check out commands such as grep (easy), awk (a bit harder) and sed (can be quite tricky).

Revision as of 15:08, 31 March 2006

What is the goal?

This script is meant to display information about what your aMuled has been up to in a way pleasing to the eyes, using AMuleCMD. Because it depends on the "show log" command, make sure you use aMule version 2.1.2 or higher.

The standard script

The script itself is quite simple:

 #!/bin/sh
 # Version 20060330
 domule() {
   amulecmd -c "$@" | grep "^ >"
 }
 domule "show log" | sed "
 /: Failed to / {s/: \(.*\)/: `tput setaf 1`\1`tput sgr0`/;}
 /: Finished downloading/ {s/: \(.*\)/: `tput setaf 2`\1`tput sgr0`/;}
 /: Downloading / {s/: \(.*\)/: `tput setaf 3`\1`tput sgr0`/;}
 "
 echo ""
 domule "status" | sed "
 /Download:/ {s/\(Download:\)\(.*\)/\1`tput setaf 3`\2`tput sgr0`/;}
 /Upload:/ {s/\(Upload:\)\(.*\)/\1`tput setaf 2`\2`tput sgr0`/;}
 "
 domule "reset" >/dev/null

Note:

  • This depends on the sh shell, the grep command and the sed command. If your system does not have sh, you will either have to install or change the first line to a shell you do have, f.e., /bin/bash

When executing this script, you get something like this:

http://qtea.nl/amule/amulelog.png

How to change the colours

The "tput set <digit>" is used to insert the colour codes. The different numbers stand for different colours. See man tput for other tricks you can do with tput.

How to remove the colours

If you don't want the colours at all, you can remove the sed commands:

 #!/bin/sh
 # Version 20060330
 domule() {
   amulecmd -c "$@" | grep "^ >"
 }
 domule "show log"
 echo ""
 domule "status"
 domule "reset" >/dev/null

Nice, but I only want to see finished downloads

This can be achieved by using the grep command:

 #!/bin/sh
 # Version 20060330
 domule() {
   amulecmd -c "$@" | grep "^ >"
 }
 domule "show log" | grep ": Finished downloading" || echo " > No finished downloads"
 echo ""
 domule "status"
 domule "reset" >/dev/null

How to use these scripts

Simply save them to a plain text file and make them executable (f.e., on linux by applying 'chmod u+x <yourscriptfilehere>'). This will work on most OS'es, except maybe for Windows since the standard version does not come with a useful command line shell.

Conclusion

There are a hunderd different things you can do with the output of "show log", only limited by your imagination ;) If you want to change the behaviour of the script you might want to check out commands such as grep (easy), awk (a bit harder) and sed (can be quite tricky).