when I type "module available", it gives information of available of modules lie this.

--------------------------------- /tool/applic/module-3.2.10/Modules/3.2.10/modulefiles ----------------------------
Applic/Abaqus_2016_sp1       Applic/FDTD-8.15.716-1       Applic/Raphael_2006.12-SP2   Applic/Synopsys_sx_C2009-sp1

and I want to save this information every 1 min. by using crontab.

so I "crontab -e" and edit like this

*/1 * * * * module add something
*/1 * * * * module list >> croninfo.txt     
*/1 * * * * module available >> croninfo.txt

but croninfo.txt is empty. It seems like "module" is not working.

how can I make module work so that I can add modules.


There are two obvious possibilities here.

First, you have to keep in mind that cron runs its commands with an environment that is normally quite different from what you get in an interactive shell launched from a logged in session. You seem to have accounted for this by adding a PATH assignment, but it's important to remember. As an addenum to this, cron runs the commands with the current working directory set to the owner user's home directory, so if that's not what you want you have to adjust accordingly.

Second, commands with the same time specifier are executed in an indeterminate order. When you write

*/1 * * * * module add something
*/1 * * * * module list >> croninfo.txt
*/1 * * * * module available >> croninfo.txt

you might think that they are going to be executed sequentially, one after the other, but in fact, cron is free to execute them in whichever order it happens to like at the spur of the moment. Depending on how long each command takes to start and execute, it's perfectly possible to have multiple different commands executing simultaneously.

If you want to execute a set of commands sequentially, often the best approach is to make a simple script that runs the commands in the correct order, and only execute that script from within cron.

Doing that will also allow you to use something like #!/bin/bash -x to get more details about the execution of the script, which can help pinpoint problems.

By the way, you don't need the /1 specifier; * and */1 are equivalent on any sane cron implementation. The /n specifier is more useful when you want n to be something other than 1; for example, to execute a command every three minutes (*/3 in the first time specifier field).

  • the problem is command "module" do not work by cron. – 최원우 Oct 20 '16 at 8:19
  • It should be something to do with the first issue that you commented how can I know what I have to append to my PATH to make module works. In addition even "module" command works well, when I type "which module", it can't find where module source is. so I dont know which path I have to append to PATH – 최원우 Oct 20 '16 at 8:22
  • @최원우 I don't know what this module command is (it's certainly not one I am familiar with), but try type module. – a CVn Oct 20 '16 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.