LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-28-2012, 02:52 PM   #1
sam_nyc
Member
 
Registered: Aug 2009
Posts: 41

Rep: Reputation: 1
How to read a file and use that to start a process


Hi,

I do lot of things with license, we have so many different application which requires different license for each. I need to find out how to pass the file name from a directory on to script?

This is what I did so, please help on the XYZ below.

Code:
#!/bin/bash
#
# If lmgrd is already executing, don't re-execute it.
#

FLEXHOME=/usr/flexlm
LMGRD=$FLEXHOME/lmgrd
LICFILE=$FLEXHOME/lic/{XYZ}

## XYZ - some server have three file, some of them have 10 files here.  
#I need to find out how to do ls take the name of the file to pass it here. 

LOGFILE=/tmp/logs/{XYZ}.log

case $1 in
'start')
        if [ -x $LMGRD ]
        then
        if [ -f $LICFILE ]
        then
        $LMGRD -c $LICFILE -l $LOGFILE
        fi
        fi
        ;;
'stop')
        if [ -x $LMGRD ]
        then
        $LMGRD -x lmdown
        fi
        ;;
*)
        echo "usage: /etc/init.d/lmgrdsh {start|stop}"
 
Old 03-28-2012, 06:48 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
I think you may need to describe the situation with a few more words than
this; I for one can't make too much sense of your request.

How is the script invoked, where does the "directory" come into the picture?



Cheers,
Tink
 
Old 03-29-2012, 08:58 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
If you need to work on multiple files, you should use an array, rather than a single scalar variable.

http://mywiki.wooledge.org/BashFAQ/005

Or are you trying to match a single file out of a directory to use? If so, you'll need to explain your requirements in more detail. Give us an example of the directory contents, which file you need to match, and how you want to use it.


In addition, I'd like to offer some general comments regarding your script:

1)
QUOTE ALL OF YOUR VARIABLE SUBSTITUTIONS. You should never leave the quotes off a parameter expansion unless you explicitly want the resulting string to be word-split by the shell. This is a vitally important concept in scripting, so train yourself to do it correctly now. You can learn about the exceptions later.

http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes

2)
It's recommended to use ((..)) for numerical tests, and [[..]] for string tests and other complex expressions. Don't use the old [..] test unless you specifically need POSIX-style portability.

http://mywiki.wooledge.org/ArithmeticExpression
http://mywiki.wooledge.org/BashFAQ/031
http://wiki.bash-hackers.org/commands/classictest
http://wiki.bash-hackers.org/syntax/...nal_expression

3)
Clean, consistent formatting makes code readable and more easily debuggable. Indent all your sub-commands, and separate logical sections with whitespace. Add comments anywhere the code isn't completely obvious (and remember, what seems obvious to you now will not be a year or so down the line).

Many people also think that it's more readable to place the "do/then" keywords on the same line as the "for/while/until/if" keywords, as it more clearly separates the outside block from the inside block.

Code:
for var in <list> ; do

	if [[ "$var" == "foo" ]]; then
		<commands>
	fi

done
4)
Environment variables are generally all upper-case. So while not absolutely necessary, it's good practice to keep your own user variables in lower-case or mixed-case, to help differentiate them.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to read a PID from a text file and kill the corresponding process sneakyimp Linux - Newbie 3 06-30-2010 02:52 PM
nfsd lots read/write, file/process causing problem mfitzpat Linux - Newbie 2 05-11-2010 02:58 PM
help with c program to read each line from text file, split line , process and output gkoumantaris Programming 12 07-01-2008 01:38 PM
How can read from file.txt C++ where can save this file(file.txt) to start reading sam_22 Programming 1 01-11-2007 06:11 PM
How can I create a pid file from a backgournd process that I start? Hackiller Linux - General 3 05-12-2004 03:37 PM


All times are GMT -5. The time now is 07:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration