Sponsored Content
Full Discussion: Reading CLI input for script
Top Forums Shell Programming and Scripting Reading CLI input for script Post 302580199 by mirni on Wednesday 7th of December 2011 11:34:02 PM
Old 12-08-2011
You can check the roots privileges by testing EUID. If EUID==0, then the caller has roots powers.

Check if the account exists: look at /etc/passwd. You can see all users there. /etc/groups stores the groups.

Lock/unlock: create a lock file and test for its existence. You can then even gather other interesting info, like when the user invoked your script (timestamp of lockfile).
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Reading Input in a Script

#!/usr/bin/sh echo "Enter reason:" echo "> \c" read $reason $reason >> access.log This doesnt work for me. Can someone tell me how I would read the input from what the person types, and then append that to the log file? Regards (2 Replies)
Discussion started by: alwayslearningunix
2 Replies

2. Shell Programming and Scripting

reading from input

Hi guys , As you know normally ' read ' statement waits for the user to press enter and then terminates the input ............. Can anyone of u tell me how do i read a single character from input without waiting for the user to press enter ................ Thanks, Nagesh. (1 Reply)
Discussion started by: nageshrc
1 Replies

3. UNIX for Dummies Questions & Answers

Reading input to create a variable in a script?

I would like to prompt for input and then use it as a variable in a script. Something like this. #!/bin/ksh echo "What is your name?: \c" read response echo "Your name is $reply" >file.txt done exit 0 What am I missing? Thanks, (7 Replies)
Discussion started by: darthur
7 Replies

4. Shell Programming and Scripting

Script for reading an input file

#!/bin/sh rpt="/export/home/legato/rpt_offsite"/test_eject.tape cat <$rpt while read line do echo $line perform routine done I am trying to read the contents of this file line by line and perform a routine for each line read. The file contents are numbers.. What is wrong with my... (1 Reply)
Discussion started by: gzs553
1 Replies

5. Shell Programming and Scripting

Reading specific contents from 1 input files and appending it to another input file

Hi guys, I am new to AWK and unix scripting. Please see below my problem and let me know if anyone you can help. I have 2 input files (example given below) Input file 2 is a standard file (it will not change) and we have to get the name (second column after comma) from it and append it... (5 Replies)
Discussion started by: sksahu
5 Replies

6. Shell Programming and Scripting

awk script - reading input lines

Can I do something like, if($0==/^int.*$/) { print "Declaration" } for an input like: int a=5; If the syntax is right, it is not working for me, but I am not sure about the syntax. Please help. Thanks, Prasanna (1 Reply)
Discussion started by: prasanna1157
1 Replies

7. Shell Programming and Scripting

[SH] Problem reading input in script

Alright, so the goal of my script is to read text from standard input and store it into a file using the ex-editor: so far i've got this, but it doesn't work. #!/bin/s read text ex $1 >> HERE text HERE I don't get any errors either, so i don't know what i'm doing wrong. (7 Replies)
Discussion started by: Bertieboy7
7 Replies

8. Shell Programming and Scripting

Perl Script Not Reading Input Files Correctly

This is one of the strangest things that's happening to me. I'm writing a new Perl script that is trying to read a file. The file is originally in .mof format, but I also saved the contents into a .txt file. As a simple test, I wrote this: #!/user/bin/perl -w use strict; ... (3 Replies)
Discussion started by: kooshi
3 Replies

9. Shell Programming and Scripting

Array from cli input

I need to create a bash array from the command line parameters. I only know how to do it when I know the number of parameters. But what do I do when I dont know the number of parameters? (1 Reply)
Discussion started by: locoroco
1 Replies

10. Shell Programming and Scripting

Read multiple input from CLI :ksh

Hi folks.. i got a requirement to red multiple directories from STDIN and store them to a variable. ex:- echo "Enter directory to add:" echo " Enter directory to add:" read value till there is input and when there is no input close the read loop and store variable into an array ... (1 Reply)
Discussion started by: bangaram
1 Replies
DOTLOCKFILE(1)							 Cistron Utilities						    DOTLOCKFILE(1)

NAME
dotlockfile - Utility to manage lockfiles SYNOPSIS
/usr/bin/dotlockfile [-l [-r retries] |-u|-t|-c] [-p] [-m|lockfile] DESCRIPTION
dotlockfile is a command line utility to reliably create, test and remove lockfiles. It creates lockfiles reliably on local and NFS filesystems, because the crucial steps of testing for a preexisting lockfile and creating it are performed atomically by a single call to link(2). Manpage lockfile_create(3) describes the used algorithm. dotlockfile is installed with attribute SETGID mail and thus can also be used to lock and unlock mailboxes even if the mailspool directory is only writable by group mail. The name dotlockfile comes from the way mailboxes are locked for updates on a lot of UNIX systems. A lockfile is created with the same filename as the mailbox but with the string ".lock" appended. The names dotlock and lockfile were already taken - hence the name dotlockfile :). OPTIONS
-l Create a lockfile if no preexisting valid lockfile is found, else wait and retry according to option -r. This option is the default. A lockfile is treated as valid, o if it holds the process-id of a running process, o or if it does not hold any process-id and has been touched less than 5 minutes ago (timestamp is younger than 5 minutes). -r retries The number of times dotlockfile retries to acquire the lock if it failed the first time before giving up. The initial sleep after failing to acquire the lock is 5 seconds. After each retry the sleep intervall is increased incrementally by 5 seconds up to a maximum sleep of 60 seconds between tries. The default number of retries is 5. To try only once, use "-r 0". -u Remove a lockfile. -t Touch an existing lockfile (update the timestamp). Useful for lockfiles on NFS filesystems. For lockfiles on local filesystems the -p option is preferable. -c For debugging only: Check for the existence of a valid lockfile. Note: Testing for a preexisting lockfile and writing of the lockfile must be done by the same "dotlockfile -l" or "dotlockfile -m" command, else the lockfile creation cannot be reliable. -p Write the process-id of the calling process into the lockfile. Also when testing for an existing lockfile, check the contents for the process-id of a running process to verify if the lockfile is still valid. Obviously useful only for lockfiles on local filesystems. -m Lock or unlock the current users mailbox. The path to the mailbox is the default system mailspool directory (usually /var/mail) with the username as gotten from getpwuid() appended. If the environment variable $MAIL is set, that is used instead. Then the string ".lock" is appended to get the name of the actual lockfile. lockfile The lockfile to be created or removed. Must not be specified, if the -m option is in effect. RETURN VALUE
Zero on success, and non-zero on failure. For the -c option, sucess means that a valid lockfile is already present. When locking (the default, or with the -l option) dotlockfile returns the same values as the library function lockfile_create(3). Unlocking a non-existant lockfile is not an error. NOTES
The lockfile is created exactly as named on the command line. The extension ".lock" is not automatically appended. This utility is a lot like the lockfile(1) utility included with procmail, and the mutt_dotlock(1) utility included with mutt. However the command-line arguments differ, and so does the return status. It is believed, that dotlockfile is the most flexible implementation, since it automatically detects when it needs to use priviliges to lock a mailbox, and does it safely. The above mentioned lockfile_create(3) manpage is present in the liblockfile-dev package. BUGS
None known. SEE ALSO
lockfile_create(3), maillock(3) AUTHOR
Miquel van Smoorenburg, miquels@cistron.nl September 8, 2009 DOTLOCKFILE(1)
All times are GMT -4. The time now is 02:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy