Date: Tue, 16 Jan 2007 15:51:46 +0300 From: "Andrew Pantyukhin" <infofarmer@FreeBSD.org> To: "linux quest" <linuxquest7570@yahoo.com> Cc: FreeBSD-questions@freebsd.org Subject: Re: Command Execution Using Script - Similar to Windows Batch File-Like Script (Coding Help) Message-ID: <cb5206420701160451y5d13e9dp9a9688110615dc6c@mail.gmail.com> In-Reply-To: <524906.28483.qm@web59207.mail.re1.yahoo.com> References: <524906.28483.qm@web59207.mail.re1.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 1/16/07, linux quest <linuxquest7570@yahoo.com> wrote: > Dear FreeBSD Communities, > > Lets say, I wanted to create a Perl script to execute a > very simple nmap command as listed below, may I know how > do I do it? > > unix# nmap 192.168.1.2 > > I know we need to save it in .pl extension. May I know > what else I need to do? > > I have researched and google this for the entire week, > but I still can't find the solution. For example in Windows, > all I need to do is to type "nmap 192.168.1.2" and save it > in a text file with the extension .bat - and everything will > be taken care of. > > I hope someone can share with me the simple coding to solve > this problem. Considering the question a subtle joke or something, let me take the bait and help you. File extensions do not matter much in Unix. File permissions do. If you want to make an executable script, you'll have to state in its first line what kind of script it is, or, more precisely, what program should interpret it. The line is usually called "shebang" because it starts with "#!". After that an interpreter must be specified. For shell scripts (you want to start with them!) use "#!/bin/sh" (without the quotes) in the first line. After that line just add more lines with commands. "nmap 1.2.3.4" is a perfectly valid command, you can just place it on a separate line. After all that you need to change permissions of this new file you've just created to allow execution. Just do: # chmod a+x <file> You can then try to execute the file either by calling it by full path or by changing into its directory and typing "./<file>" Good luck!
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?cb5206420701160451y5d13e9dp9a9688110615dc6c>