Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Jan 2007 13:35:40 +0100
From:      "Niclas Zeising" <niclas.zeising@gmail.com>
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:  <bc292860701160435sce81714oacb30a537260551f@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.
>
> Thank you so much, guys :)
>

I think you're better of with a sh shell script for these simple kinds
of task. Perl might be a bit of overkill.
Somethink like this might do the trick:

#!/bin/sh
nmap 192.168.1.2

You can add "| mail [yourmail]" if you want the output mailed
somewhere  (if you have mail set up properly on your machine) or just
redirect the output to a file if you like. Otherwise the output of the
script (i.e. nmap) will end up on stdout.

Save the file with a .sh extention, chmod u+x file to make it
executable, and run it.
sh(1) has more info on how the sh shell works and how to write scripts
in it. It's far more sofisticated than the windows .bat-thingie ;)
HTH!
//Niclas
--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bc292860701160435sce81714oacb30a537260551f>