{"id":4303,"date":"2011-10-05T11:44:15","date_gmt":"2011-10-05T06:14:15","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=4303"},"modified":"2012-06-12T11:01:33","modified_gmt":"2012-06-12T05:31:33","slug":"making-your-own-custom-command-for-a-script-file-which-can-be-executed-from-any-user","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/making-your-own-custom-command-for-a-script-file-which-can-be-executed-from-any-user\/","title":{"rendered":"Making your own custom command for a script file which can be executed from any user."},"content":{"rendered":"<div>One way to execute the script file via command can be making of alias and put it in .bashrc , but this will only be available to that user. So for creating a user-defined command which can be executed from any where for any user following steps need to be followed:<\/div>\n<div>1. Make a script file which has the set of commands to be executed and add &#8216;x&#8217; permission for all.e.g.<\/div>\n<p>Here is a script file(\/home\/anuj\/myscript\/myscript.sh) which echo&#8217;s current directory on the terminal.<\/p>\n<p>[java]echo $PWD[\/java]<\/p>\n<p>2. Make a symbolic link \u00a0mycommand pointing to myscript.sh in \/usr\/bin or \/sbin\/ or \/usr\/sbin directory \u00a0(Differences between them can referred from here).<\/p>\n<p>[java]<br \/>\ncd \/sbinln -s \/home\/anuj\/myscript\/myscript.sh mycommand<br \/>\n[\/java]<\/p>\n<p>Now you can use command &#8220;which&#8221; to see which file will executed if we type the command named &#8220;mycommand&#8221;<\/p>\n<p>[java]<\/p>\n<p>which mycommand<\/p>\n<p>Output: \u00a0\/sbin\/mycommand<\/p>\n<p>anuj@intelligrape:\/tmp$ mycommand<\/p>\n<p>Output: \u00a0\/tmp\/<\/p>\n<p>[\/java]<\/p>\n<p>Its done! \ud83d\ude42 \u00a0Next question would be where we can use it to make our life easier??.\u00a0Well ! Generally we have deployment script for that we need to switch to user and then we need to run the script file\u00a0instead of doing that we can make a softlink of the script file and put it in the \/sbin or \/usr\/sbin etc. Like some software packages like apache put softlink to there script file in \/sbin.e.g. \u00a0a2ensite is a softlink to a2enmode in \/usr\/sbin which is a executable script file.<br \/>\nThere can be some better way to achieve the same so suggestions are most welcomed.<\/p>\n<p>Hope this helps you guys !<\/p>\n<p>Anuj Aneja<br \/>\nIntelligrape Software<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One way to execute the script file via command can be making of alias and put it in .bashrc , but this will only be available to that user. So for creating a user-defined command which can be executed from any where for any user following steps need to be followed: 1. Make a script [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2},"categories":[1],"tags":[260],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/4303"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=4303"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/4303\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=4303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=4303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=4303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}