General :: Cannot Add Fractions In Loop Using Bc In A Script?
Feb 11, 2010i have tried a lot to add floating values in while loop using bc, but no sucess!!!
script is :
read a1
read a11
[code]....
i have tried a lot to add floating values in while loop using bc, but no sucess!!!
script is :
read a1
read a11
[code]....
I have a mytext file with month and year as two separate fields. likemytext fil
08 2010
09 2010
10 2010
........
........
........
I want to read the values of each field i.e., month and year into an awk script.
./test.sh: line 3: syntax error near unexpected token `cd'
./test.sh: line 3: `cd $f'
--------------------------------
[code]....
I have a requirement to check the following conditions..If my folders are not A and B then list files in the directory else no listing the filesso my if loop is some thing like this.
Code:
if [ $dirName = "C" && $dirName != "A" && != "B" ] then
ls -la
[code]....
I have bash 4.0. I used the following for loop example, but all it outputs is "{1..10} instead of the actual numbers one through ten. why?
Code:
for a in {1..10}
do
echo -n "$a "
done
I have a server hosting 100+ websites. I need to quickly identify which websites are configured with a database. There are way too many to manually check every website for a PHP file with a database name. So, I created a list of all databases from MySQL and put them in a text file. I then exported the text file to a shell variable and used it in a for loop.
bash variable
Code:
DBLIST=`cat dblist.txt`
Example of $DBLIST
Code:
db1 db_testing2 database_clientname production words4cheap
for loop
Code:
for db in $DBLIST; do find . -type "f" -iname "*.php" -exec grep -i $db '{}' ; -print; done
Note: my find statement starts searching at . which is the directory that contains all of my websites and their data, each website is setup in a sub directory, identified by it's domain name.
Example: I'm in /var/www. Beneath /var/www are a list of directories:
[URL]
However, this is taking too long (it's been running most of the day) and I was wondering if there wasn't an easier way to accomplish what I'm trying to achieve?
I am trying to do some shell programs. I tried some sites regarding the while loop, they give the structure as:
Code:
while [ n1 -lt 500 ]
do
echo $((n1+100))
done
But the below code also worked for me:
Code:
while ((n1 > 500))
do
echo $((n1+100))
done
By using (( )) I could use while, for. But the documentations didnt follow this way. I mainly use this for datastructure programming.
The problem of loop detected when resolving the name from dns.Why the problem of loop detected comes when name is resolving from dns.
View 4 Replies View RelatedI am having trouble getting the while loop to execute in the ssh command:ssh $USERID@serverX "while read line do echo $line done<$list_dir/cost_feed.lst.old"Error:bash: -c: line 1: syntax error: unexpected end of fileI have managed to use simpler commands with ssh like:ssh $USERID@serverX "pwd; cp x y"I expect that I need to add some combination of escape characters or semicolons
View 3 Replies View RelatedDo you know how to convert an animated GIF (only two pics in loop) to FLV or AVI?
I didn't search for a Microsoft alternative that maybe could run with WINE, because I really prefer a native one; also a java version will be fine.
While I was trying to compile a C shared object library, I accidentally created two symbolic links which point to each other. Is there a way to get rid of them without nuking the whole directory? I read that the only way to break a symbolic link is to delete the file it points to, but I'm sure there must be another way.
View 3 Replies View RelatedI have a large NFS share with a variety of software ISOs on it. I've only tried this on Red Hat Enterprise Linux, but when trying to do the following, the mount comes back with an error indicating no permissions to mount. Why would this be happening?NFS is mounted thusly:mediaserver:path/to/isos /media/nfsThis is the mount call that failsmount -o loop /media/nfs/product.iso /tmp/productIf I copy the ISO, there is no issue. The NFS share is mounted rw.How can I loop mount the ISO from the NFS share without copying it first?
View 2 Replies View Relatedhow to convert an animated GIF (only two pics in loop) to FLV or AVI? I didn't search for a Microsoft alternative that maybe could run with WINE, because I really prefer a native one; also a java version will be fine.
View 1 Replies View RelatedI multi-boot several Linux distributions with an assortment of additional data partitions. I get frustrated whenever fsck is forced during boot. (It ONLY happens when I'm in a hurry don't you know...) So I wrote a script to automate forced fscking when I do have the time. (And/or while I'm doing something else in another workspace.
Because I multi-boot, I've learned that udev doesn't always assign the same device name to each drive for all distributions. I've had the same partition identified as hda5, sda5, & sdb5 by different distributions (without doing anything to affect the boot order) So my solution is to keep a list of partitions in a specific file on each distro with valid device names according to that distribution's udev process. Actually I'd use LABEL= instead but the labels don't show up in /etc/mtab, and I like to make sure a partition isn't mounted before I try to fsck it.
I can make this work in a for loop using cat. But I've seen so many things about NOT using cat that I wanted to rebuild my script. I can make this work with a redirect instead of cat via a while loop, But I "LIKE" old style for loops. But I can't seem to find a way to make a redirect work with one. I thought this might make a good first �LinuxQuestions.org� question. I'm also open to any other suggestions on better/alternative methods... Is it possible to redirect from a file into an actual for loop?
My script is as follows:
Code:
#!/bin/bash
# FsckEm I script to force file system checking on unmounted ext2/ext3/ext4
# partitions in preselected list. FsckEm accepts no options. Partition
[code]....
I wrote a script for copying mp3 files to my girlfriend's mp3-player and it looks like this:
Code:
mount /dev/sdc /test -o sync
for i in *.mp3; do
[code]...
How do I write a loop command to periodically check a given folder and then create a djvu file from any pdf it finds.pdf2djvu works great but I'm looking to set up a "hot folder" for general office staff to use.
View 3 Replies View RelatedI have a directory that contains some files (over a 1,000) that have a '' in the filename. There are also some good files that I need to keep. therefore I need a script to delete based on inode.
What I have thus far:
list="$(ls -il /opt/PC/log/*RPOUT*.xml)" #this gives me the list
# I need to get the inode of.
for i in $list
do
find . -inum $i -exec rm -i {} ;
echo "delete file" $i >> /home/me/tmp/del_inode.txt
done
echo 'completed'
I know this is not right ... what I know is is the 'find' is. I need to loop through the $list gleaning inodes to get all the files with '' delete. I'm not sure how. The $i gives me the whole line. I just want the first position. set $() does not seem to work ...
I'm trying quickly dig through our VPN logs for a list of class A ips , and I'm having trouble. I have a file with a list of numbers, one per line. I'm wanting to incorporate each number into an extended regex:
Code:
for i in `cat ips`; do zgrep -E '[[:space:]]$i(.[0-9]{1,3}){3}[[:space:]]' vpn1/2009.08.20.log.gz; done
If I substitute one of the numbers in for $i, it works for that number. For example:
Code:
for i in `cat ips`; do zgrep -E '[[:space:]]58(.[0-9]{1,3}){3}[[:space:]]' vpn1/2009.08.20.log.gz; done
I think the loop is passing literally "$i" to zgrep instead of its value due to the tics, and I can't figure out how to resolve this. I can't remove the tics b/c zgrep doesn't like that. Putting a backslash in front of $i doesn't work.and the number loop seems to be working fine:
Code:
for i in `cat ips`; do echo $i; done
1
14
27
43
[code]....
I want to figure out what is going on in this small script.Its really strange.I think its the infinite loop again.All I want to do is to collect some data from the zenity dialog box in an array and then echo it.Here is the code
Code:
#!/bin/bash
#export PS4='+${BASH_SOURCE}:${LINENO}:${FUNCNAME[0]}: ' debugging info
[code]...
Totally new to programming (as of this morning) so please bear with me I have a bash script that stops working after the first while loop.
#part 1
While
doThisThatThe Otherdone
#part 2
While
doMOreMoreMoredone
Every arguement above the first loop completes (including the first loop itself) but anything below (incuding the second while loop) doesn't finish. I know that it isn't a problem with an unending loop... it seems to be something about the While loop that I'm not understanding... but I can't figure it out. I just need arguments below the first while loop to take place.
I am posting this just for the sake of curiosity. I am trying to feed a while loop structure with a command output, but using the bash built-in I get the error "ambiguous redirect":
Code:
while read line
do
[code]....
I tried installing a wallpaper and it said that I would have to open up a web browser to view it, but when I did it launched over and over again, and I couldn't even properly shutdown, I had to hold down the power button. But it seems fine now, but from now on I'm avoiding downloading Wall Paper that requires you to use a web browser to view and download.
View 1 Replies View RelatedI have to format 4 years worth of awstats data "static" for a client and then move it to their new server.I don't want to run the commend to do this 48 times. If possible I would like to use a bash script that uses the folders in a directory so the script knows which year-month to do this for me and which folder to place the output in.
View 5 Replies View RelatedI'm trying to do substitutions to a file based on passed variables.
For example, I have a file called test.txt that has 5 lines:
What I want to do is to go through that file, line by line and check for the presence of a passed variable in that line. If I have a match, then substitute and print, otherwise print line as is. My problem arises in that the number of variables is well, variable.
The code I started with was the following:
Code:
What I was hoping for was test.out to look like this:
What I get is a much longer file like this:
This makes sense after thinking about it but is there anyway to get an output like the first case?
I am trying to write a script that will find any user on the server running more than one instance of the epiphany web browser process, then kill all their epiphany pids. (This is necessary sometimes to cure lockups, and repeat processes are the telltale sign in this case). I have tried implementing the until loop:
Code:
USER=`ps aux | grep epiphany | grep -v grep | sort | uniq -d -w 5 | awk '{print $1}'`
until [[ "$USER" == "" ]]
do
ps aux | grep epiphany | grep -v grep | grep $USER | awk '{print $2}' | sudo xargs kill
done
Unfortunately, the script only calculates the USER variable once at the beginning of the script. Fair enough, that's how it's written. My question is, how would I get the USER variable to update for each pass of the until loop so that it could cure multiple users of this ailment if necessary? That is, calculate $USER, kill their epiphany pids, repeat those two steps until the $USER variable comes up blank, then exit.
First off, this isn't the usual "physical" feedback of a speaker being too close to the mic. This mic is part of a headset so there's no way for the output and input to overlap and cause feedback. This mic has worked perfectly for me in the past, but I recently re-installed my OS and it hasn't worked since.
It seems as if my audio out is getting redirected to microphone in. If I open up and sound recording program while I have some audio being output, the output will get echoed back in through the microphone channel, although any actual microphone input is never picked up. I can blow or scream into the mic and there's no indication at all that Linux is picking it up.
I'm running ArchLinux with ALSA. I've gone into alsa mixer and played with just about every channel in every way I can think of, and none of the options seem to fix the problem.
How should I fix this? I use my mic pretty much constantly when I'm on the computer, being without it sucks.
I have a java server console program that I have configured xinetd to start when connection comes in on a given port and then the program runs in an infinite loop receiving inputstream from telephone exchanges. The thing is, when a new chunk of stream comes from the exchange xinetd forks a new process each time. I tried setting the wait parameter to yes and restarted the deamon, but no success. How can I stop this behavior and have the deamon just direct the stream to the process already running? Am I missing something in my config or is it just incorrect?
My config is as follow:
defaults
{
instances = 60
log_type = SYSLOG authpriv
log_on_success = HOST PID
log_on_failure = HOST
cps = 50 10
}
includedir /etc/xinetd.d
And then my actual config,
service aos_larmar
{
socket_type = stream
protocol = tcp
user = root
type = UNLISTED
wait = yes
instances = 256
server = /home/gunnl/java/start.sh
port = 5204
disable = no
}
My server OS is, Red Hat Enterprise Linux ES release 4 (Nahant Update 7)
I have hundreds of files in one directory, is there a simple command or pipes of command I can use to append them together? I don't want to use any loops.
View 4 Replies View RelatedI made a disk image of a vfat fat16 using:
Code:
dd if=/dev/sda of=image_drive.img
I would like to mount it to /mnt/vfat using mount and loop. Is it possible to be mounted?
I tried to find an answer to whatever is happening with my sh, tried a few approaches, but none is working the way I planned... the loop quits with exit 0, runs once, if I comment out 'ffmpeg' line, it runs N times as it should - ffmpeg does not error out other than 0.
Code:
find . | grep .mp3 | while read filename do
newfilename=`echo "$filename" | tr ".mp3" ".ogg"`
ffmpeg -i "$filename" -acodec libvorbis -ac 2 -aq 4 -y "$newfilename"
echo inside #4debug
done
echo outside
This sh runs once, echoes "inside" 'n "outside" once, exits with '0'... unless ffmpeg commented out. I also tried to feed the loop with: done < /tmp/fname.list. BTW, this works well - but I am very interested in the >while read< loop giving up.
Code:
for i in *.mp3; do ffmpeg -i "$i" -acodec libvorbis -ac 2 -aq 4 -y "$(basename "$i" .mp3).ogg"; done