From owner-freebsd-questions@FreeBSD.ORG Sun Apr 6 12:42:47 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 806101065671 for ; Sun, 6 Apr 2008 12:42:47 +0000 (UTC) (envelope-from derek@computinginnovations.com) Received: from betty.computinginnovations.com (mail.computinginnovations.com [64.81.227.250]) by mx1.freebsd.org (Postfix) with ESMTP id 2D4C28FC15 for ; Sun, 6 Apr 2008 12:42:46 +0000 (UTC) (envelope-from derek@computinginnovations.com) Received: from p28.computinginnovations.com (dhcp-10-20-30-100.computinginnovations.com [10.20.30.100]) (authenticated bits=0) by betty.computinginnovations.com (8.14.2/8.14.2) with ESMTP id m36CgcDU031237; Sun, 6 Apr 2008 07:42:39 -0500 (CDT) (envelope-from derek@computinginnovations.com) Message-Id: <6.0.0.22.2.20080406073457.02527d90@mail.computinginnovations.com> X-Sender: derek@mail.computinginnovations.com X-Mailer: QUALCOMM Windows Eudora Version 6.0.0.22 Date: Sun, 06 Apr 2008 07:42:27 -0500 To: "Rance Hall" , freebsd-questions@freebsd.org From: Derek Ragona In-Reply-To: <845c0f80804041321j44439881yb67458980edab102@mail.gmail.com > References: <845c0f80804041321j44439881yb67458980edab102@mail.gmail.com> Mime-Version: 1.0 X-Antivirus: avast! (VPS 080406-0, 04/06/2008), Outbound message X-Antivirus-Status: Clean X-Virus-Scanned: ClamAV 0.92.1/6628/Sat Apr 5 20:14:00 2008 on betty.computinginnovations.com X-Virus-Status: Clean X-ComputingInnovations-MailScanner-Information: Please contact the ISP for more information X-MailScanner-ID: m36CgcDU031237 X-ComputingInnovations-MailScanner: Found to be clean X-ComputingInnovations-MailScanner-From: derek@computinginnovations.com X-Spam-Status: No Content-Type: text/plain; charset="us-ascii"; format=flowed X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Subject: Re: need a shell script that can be executed manually or as part of the rc process. How can the script detect WHERE it is being called from to know how to handle various options. 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: Sun, 06 Apr 2008 12:42:47 -0000 At 03:21 PM 4/4/2008, Rance Hall wrote: >I have a sh script im working on that is going to be able to run by >the init/rc process. That same script can also be run after the >system is started. > >I need a way to have the sh script detect WHERE in the boot process >the server is when it is being executed. > >for example, once a login prompt appears there should be a getty running. > >prior to that time there shouldnt be a getty running, and if there >isnt a gettty running, then the script must be called from the rc >process and therefore I can do X instead of Y which I do when the >system is fully operational. > >This is my thought process but I dont understand how to carry it out, >or if the thought process actually makes sense. > >is there a better way for me to do what Im trying to do, and if there >isnt and Im on the right track, how do I do what Im asking? There are a couple approaches you can take: One simpler would be to use a cron job that runs @reboot I believe these cron jobs would be run after the system is booted in multiuser. You could experiment to determine if this is the case. An alternative which would be more complex would be to write an rc script that runs from /usr/local/etc/rc.d. Such a script would need to support at least the standard parameters of: start stop status You can easily add: restart where the restart function calls the stop and then the start functions. In the start function if you need to verify a getty running, you can do: ps -ax|grep getty then test $? to see if it is 0 and a getty is found, or that it is 1 and the getty is not found. -Derek -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.