Programming :: Read A Config Variable Into A Script?
Jun 8, 2010
What's the best way to read a value from a configuration file into a script?I'm trying to get the command_file vaule from nagios.cfg into a script, this works but what's the best way to do it?
Code:
command_file=$(perl -F= -lane 'print $F[1] if /^[[:space:]]*command_file[[:space:]]*=/' /etc/nagios/nagios.cfg)
View 5 Replies
ADVERTISEMENT
Aug 21, 2009
I'm trying to read content of file to variable and use this variable in for loop. The problem is, when I have c++ comment style in file - /*. Spaces in line are also interpreted as separated lines.
For example:
Code:
Changing $files to "$files" eliminate these problems but causes that whole content of variable is treated as one string (one execution of loop).
View 6 Replies
View Related
Jul 14, 2010
I am trying to write a script which can read the names of all folders within a given folder into separate variables. In effect, if a folder contains a folder "Folder1", "Folder2", "Folder3", the script would read those names into variables such as:
Variable1 = "Folder1"
Variable2 = "Folder2"
Variable3 = "Folder3"
I have tried fiddling with the find . command, but without any success.
View 3 Replies
View Related
Sep 24, 2010
I created the following.
x="top
middle
bottom"
I would like to make the following work.
while read line
do
echo $line
done
instead of importing a file I would like to use the variable $x I tried using pipes, but with no luck. My goal is to read one line at a time, but not have to export my data to another file, I would like to keep it all within one script.
View 3 Replies
View Related
Feb 27, 2011
At my wit's end I can't find anything that I understand well enough to use. This is for a Unix class, we are working with shell scripting. File1 has 5 in it and File2 has 100 in it.The teacher wants us to read the values then do the math. This is what I have so far:#!/bin/bashvar1='cat File1'var2='cat File2'var3=`echo "scale=4; $var1 / $var2" | bc`echo The final result is: $var3
View 9 Replies
View Related
Apr 7, 2010
my script has a variable which comes in the form +00.00 +0.00 -00.00 or -0.00 (the numbers can be any in that form) for any that have a + symbol I need to remove the +, but if it has a - symbol it needs to stay.
i need to make a new variable with the string from the old variable btut without any plus sign. I have tried a lot of different ways with no success, each thing I tried either left the + or removed the entire string. I think this should work but doesn't
foo=+12.40
bar=${foo#+}
View 4 Replies
View Related
Apr 25, 2011
how I can search within a variable and assign the results to a new variable. I'll use the following as an example -
cars="Audi BMW Cadillac Chevy Dodge Ferrari Ford Mercedes"
list=`echo ${cars} | egrep -o '<A?+|<C+'`
with the echo command I get the following output assigned to list -
A
C
C
What I'd like to get for output is -
Audi
Cadillac
Chevy
how I could do this regardless of upper/lower case letters?
View 5 Replies
View Related
Apr 28, 2010
included shell script inside c program, and i wanted to assign the value of c variable to shell variable..Can any one please suggest me how to do it?
View 8 Replies
View Related
May 14, 2010
I installed Chrome straight from the Google webpage. But, it kept crashing. So I've uninstalled it to go back to Firefox, which I never uninstalled. Problem is, now, links in Evolution and Gwibber no longer work! It's still trying to open Chrome. Presumably I have to edit a variable or config file with the path to the browser in it? Where would I find this?
View 2 Replies
View Related
Mar 17, 2011
This loop is part of a bash script which takes multiple arguments.
Code:
for ((i=1;i<=$number;++i)) ; do
offset=$(($i+5))
[code]...
View 3 Replies
View Related
Apr 27, 2011
I have two terminals open and I want to save the current path in a variable and read it from the second terminal that I have open.
Then in the first terminal I type:
Code:
A=$(pwd)
And in the second I type:
Code:
echo $A
that doesn't work though.
I have tried also with
Code:
export A=$(pwd)
and
Code:
alias A=$(pwd)
but nothing seems to work. Is there a way to do this?
View 4 Replies
View Related
Nov 11, 2010
I have a problem when i ried run this command (export HISTTIMEFORMAT="%F %T ") on slackware 13.0. the answer is the following (-bash: HISTTIMEFORMAT: readonly variable) I am running this command on the bash like root.
View 2 Replies
View Related
Nov 8, 2010
I googled and tried to find an easy step by step-by-step guide on how to use a bash script read a variable from a file. This is the way I did it (but it does not really work so something is wrong, but what?) (testfil2 contains one line that readsidnumber=1578
#!/bin/bash
value="/home/user1/Desktop/testfil2"
echo $value
kill $pidnumber
View 4 Replies
View Related
Mar 2, 2011
I have a recent install of ubuntu 10.10 on a brand new rig, and everything appears to be working properly but I get these 2 errors during bootup that seem to make the book process take a bit longer than expected but haven't actually noticed a problem in performance.
[6.394416] hub 3-1:1.0: config failed, can't read hub descriptor (err -22)
[6.752860] hub 3-2:1.0: config failed, can't read hub descriptor (err -22)
I have been unable to find a site with information on what err -22 means. From what little I have found on the issue it seems to be something with the usb 3.0 hubs on the back of my motherboard?
Code:
[0.864023] PCI: Using ACPI for IRQ routing
[0.864024] PCI: pci_cache_line_size set to 64 bytes
[0.864081] reserve RAM buffer: 000000000009dc00 - 000000000009ffff
[0.864082] reserve RAM buffer: 00000000df7e0000 - 00000000dfffffff
[0.864083] reserve RAM buffer: 000000021f800000 - 000000021fffffff
[0.864120] NetLabel: Initializing
[0.864121] NetLabel: domain hash size = 128
[0.864122] NetLabel: protocols = UNLABELED CIPSOv4
[0.864127] NetLabel: unlabeled traffic allowed by default ....
View 1 Replies
View Related
May 2, 2010
I am looking for a clue in shell or ant script, where I excecute a binay file on linux. For example ./myfile.bin which ask me few questions.
./myfile.bin ...........................100%
I would like to automate this process where I want to pass the hostname as a variable or read from a file is it possible? If yes any sample`s on this. I can do if this was a shell script ($1) but not sure when its binary.
View 8 Replies
View Related
Nov 24, 2009
I have a computer running Fedora 11. I wanted to use samba in my office. So I configured the /etc/samba/smb.conf ,but it did not work well : Windows can find samba,but when I tap in username and password,samba request them again , and the same thing continues in a loop. So I copied another computer's smb.conf (which is also a Fedora 11,samba runs well in this one).I copied this file to /etc/samba/ ,then samba can't satart up . I read from /var/log/samba/log.smbd.log : Unable to open configuration file "/etc/samba/smb.conf": Permission denied Even if I use: chmod 777 /etc/samba/smb.conf
why I can't login samba from Windows:
[global]
workgroup = MYGROUP
server string = Samba Server Version %v
; netbios name = MYSERVER
; interfaces = lo eth0 192.168.1.99/24
[Code]....
View 3 Replies
View Related
Aug 21, 2010
I would like to set up three directories-
1) RW public directory
2) R-public, RW-me
3) Private dir (my /home/me)
BTW, I set all file permissions (recursively) to 777 until I can get this to work...
1) So far I have got 1 samba share working Read only with the following: [Music]
[Code]...
Guests can read it okay but user 'JoeBleaux' can't write to it...
2) I can't get the public read-write dir to work, again, it can be read by everyone but no one can write to it. Here's my broken config for this share: [Uploads]
[Code]...
3) I can't get the private dir to work. Here's my broken config for this share: [HomeDir]
[Code]...
View 4 Replies
View Related
Dec 4, 2010
i want to pass variable in mysql qyery in c programming
View 1 Replies
View Related
Mar 8, 2011
I have a server listening on incoming client connections. Once the client establishes SSL connection with the server, the server waits on read() from the client. Only Client can disconnect the connection. I want to have a timer in the server program to wait for x secs after read() and then disconnect the Client connection.
View 3 Replies
View Related
Mar 25, 2011
I have beat this enough and don't get what should have been a very simple thing to do. I build a variable;
Code:
CLIST=java,lua,python,php,perl,ruby,tcl
CLIST will be used by another bash script but I need to replace the commas with a space. I
[code]...
View 2 Replies
View Related
Apr 9, 2010
How would I go about defining a variable from a document name. Example:document01.doc I want to take the 01 and set X to equal integer 1.
View 1 Replies
View Related
Jun 2, 2010
I need to replace JAVA_OPTS= with JAVA_OPTS=<some_value>.I need to give "" value at the end of the replacement. I have tried with the following but it is not working: sed -e "s|JAVA_OPTS= |JAVA_OPTS=<some_value>"
View 2 Replies
View Related
Jul 23, 2010
I have been searching most of today and am stuck on getting a variable into an awk portion of my bash script. I have this working:
Code:
#!/bin/sh
SRC=/var/log/mail.log
DEST=/var/www/output/myFile.txt
VAR=userName@myDomain.tld
[code]....
Can awk take a shell variable? Or do I have to do something completely different?
View 11 Replies
View Related
Jul 1, 2010
In C++ what does the suffix, "*" mean appended to a variable type, e.g., "char* variable1;"?
View 3 Replies
View Related
Nov 5, 2010
Following is the way I saw a variable initialized in C
Code:
static const unsigned int rtl8139_rx_config =
RxCfgRcv64K |
(RX_FIFO_THRESH << RxCfgFIFOShift) |
(RX_DMA_BURST << RxCfgDMAShift);
on following link
[URL]
I have initialized variables in past but above initialization I could not understand what is it?
View 4 Replies
View Related
May 16, 2011
problem statement:
pattern_search="Exam Name"
sed -n "/$pattern_search/,/hello/"p tmp5 | awk '{if ( $4 != 0 && $4 ~ /[0-9]+.*[0-9]*/ ) print "$pattern_search" " " $0 }'
"tmp5" is a file. this is printing output as
$pattern_search value1
i.e value of $pattern_search is not getting substituted. i am expecting output as
Exam Name value1
View 3 Replies
View Related
Feb 5, 2010
how shall I print each variable separately using a generalized form. I tried writing the following within a for loop...Code:echo $(echo a$(echo $i)$(echo $j))which did yield no result. So what shall I write??
View 3 Replies
View Related
Mar 8, 2011
I have the following input:
Code:
Event 1............................................................
full_name: JENNY_JENNINGS genre: f
age: 32
[code]....
But as you can see in the input, in the 2nd "Event", the line containing "age" is not present, but in the output my code is printing the 1rst age value twice. The correct output should be blank in the age field for 2nd line in the output like this:
Code:
full_name|genre|age|code
JENNY_JENNINGS|f|32|15a
JOHN_JOHNSON|m||23c
MARY_JEAN|f|25|11d
What is wrong in my code? how can I fix it? * I�m using ubuntu 10.10
View 12 Replies
View Related
Apr 22, 2011
How are environment variable set in tcl? I tried "set $env(MYVAR) xxxx" but it didn't work.
View 1 Replies
View Related
Apr 14, 2011
i'm trying to execute a shell script, i'm trying to use the values in an array for use in a sed command:
sed -n '/Sales ID: ${array[$i]}/,/Totals:/p'
that command creates empty files. so my guess is that its not recognizing the array as an array but as text?
how would i be able to utilize the array in the command? i got it, didnt think that if i doubled up the single quotes that it would work, but this worked:
sed -n '/Sales ID: '${array[$i]'}/,/Totals:/p'
View 4 Replies
View Related