But maybe more importantly, passing unchecked data directly to the shell is a security no-no. In your case, anyone who can create a file within the working directories of this script can execute any command as the user executing the script. So for example, if you plan to use this script from root's crontab and parse through some data files in joe's home directory, joe could very quickly do some nasty things (i.e, touch "; cat /etc/shadow | mail joe ;")
OK, maybe this example is a little far fetched for this innocuous script, but it's a good habit to avoid single-argument system... if only for the reason that spaces and quotation marks in filenames won't Just Work. Better to use the multi-argument form which bypasses the shell, solving all of these problems:
Now the arguments get directly passed via exec, and not through the shell, so the filenames can contain any stuff at all (including spaces & quotes) and the script still works as you'd expect (without doing anything unexpected/insecure).system("/bin/cp", "-f", "$dirname/$file", "malign.top"); system("/bin/cp", "-f", "$dirname/$file", "get-model.top"); system("/usr/local/modeller6v2/bin/mod6v2", "$dirname/malign.top"); system("/usr/local/modeller6v2/bin/mod6v2", "$dirname/get-model.top");
blokhead
In reply to Re: automating linux commands in perl
by blokhead
in thread automating linux commands in perl
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |