From owner-freebsd-questions@FreeBSD.ORG Tue Jan 16 12:51:48 2007 Return-Path: X-Original-To: FreeBSD-questions@freebsd.org Delivered-To: FreeBSD-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 672E016A412 for ; Tue, 16 Jan 2007 12:51:48 +0000 (UTC) (envelope-from infofarmer@gmail.com) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.169]) by mx1.freebsd.org (Postfix) with ESMTP id 0185313C448 for ; Tue, 16 Jan 2007 12:51:47 +0000 (UTC) (envelope-from infofarmer@gmail.com) Received: by ug-out-1314.google.com with SMTP id o2so1517027uge for ; Tue, 16 Jan 2007 04:51:47 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=bhQuRXz0SpZ8X3YLkvs+/qM8PcuaaIQ85maHfNPE0XtEiONrKWq3BT8XokCd32Nv5sXnuzFr6pyNm0smmNS9HA8K11eklEiuc57K4cgr/LuPAtyBST3Rz7P5ScTnjhbcPiZmWFhY/JIUdzK6Xe13EYP4gDyNU4Q5FFDL8QtamLE= Received: by 10.82.120.14 with SMTP id s14mr1045182buc.1168951906459; Tue, 16 Jan 2007 04:51:46 -0800 (PST) Received: by 10.78.164.20 with HTTP; Tue, 16 Jan 2007 04:51:46 -0800 (PST) Message-ID: Date: Tue, 16 Jan 2007 15:51:46 +0300 From: "Andrew Pantyukhin" Sender: infofarmer@gmail.com To: "linux quest" In-Reply-To: <524906.28483.qm@web59207.mail.re1.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <524906.28483.qm@web59207.mail.re1.yahoo.com> X-Google-Sender-Auth: 7fe7369c06d7a623 Cc: FreeBSD-questions@freebsd.org Subject: Re: Command Execution Using Script - Similar to Windows Batch File-Like Script (Coding Help) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Jan 2007 12:51:48 -0000 On 1/16/07, linux quest 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 You can then try to execute the file either by calling it by full path or by changing into its directory and typing "./" Good luck!