General :: Create BASH Script To Process Multiple Inputs On Read

May 26, 2010

First post from a very new Linux user....I am trying to create a BASH script that will allow user to provide multiple directory names, Checks if the directory exists and if not create the directory.

I am using the following code:

Which works fine as long as the user enters a single directory name. How can I modify this so it will process all directory names user enters on the read response?

View 5 Replies


ADVERTISEMENT

General :: Bash Script To Read Csv File With Multiple Length Columns

Jul 27, 2011

I've searched everywhere and I can't come up with a good solution. For each line I need to find the average, min, and max. I've seen plenty of solutions where the number of columns is fixed, unfortunately for me these lines can get pretty large. My thought was to read each line individually into an array, loop through the array and find the avg, min, and max that way but i haven't had much luck. I can read each line using a while loop but I'm having trouble with the array part, or perhaps that's not the best solution?

View 14 Replies View Related

General :: Run Script From Another With Multiple User Inputs And Expect

Jun 5, 2011

I am literally bashing (pun intended) my head against the keyboard at this minute! I am trying to automate a script via cron for my centos server. The script requires two user inputs (e.g. read VAR). However, I do not want to edit the original file, as I would like to be able to run it normally as well. It is also made by someone else, and so if an update becomes available, it will be easier to install. My idea is that i create a cron script, to run this second script from, and the only way i could find was with expect. However I am having troubles, In order to test out expect, I have created the following:
test.sh

[Code]...

It looks as if the second input is completely ignored ?! what i am doing wrong? or if there is a more elegant solution to running a script from a script with user inputs?

View 2 Replies View Related

General :: Create A New Background Process In A KSH "while Read" Loop?

Jun 20, 2010

When I add the line (sleep 5 ) & in the script then the "while read" loop does not read all lines from the file, but only prints the first line.But when I remove the ( sleep 5 ) & from the script, then the script prints all lines as defined in the file.And how to solve the problem? I want to create a new process (for which the sleep is just an example) in the while loop:

$ more test
#!/bin/ksh
while read -r line ; do

[code]....

View 1 Replies View Related

General :: How To Make BASH Script Yes / No User Input Query Terminate With 3 Invalid Inputs?

Mar 16, 2010

I have a BASH script which at one point asks the user a yes/no question. I want to make it so that if the user types in an invalid input 3 times consecutively then the BASH script will echo an error and terminate with exit status 1.

View 9 Replies View Related

Programming :: Read Multiple Input With Bash?

May 7, 2010

As I'm starting to learn bash scripting I'm trying to automatize some tasks I usually perform. I have a notification mail I need to send several times a day. It has this structure:

Quote:

Dear user,
blah blah blah blah

You need to contact the following people:

[code]...

To replace "user", I found this:

Code:

read -p "Please enter username: " username
echo "Dear $username,"

Which probe to be very useful with other simple notifications like this. But I don't know how to manage the email addresses as they are usually more than one and could vary from 1 to 10. They should appear one above the other. I found this: "Here is a little work around. The only thing the user needs to do is hit enter without anything else on a line and it will close out"

Code:

#!/usr/bin/ksh
word=a
until [[ $word = "" ]];do

[code]....

I tried to use it and modify for my needs but I failed, I don't realize yet how can I use it. If possible, I would like to use the until loop like the above example just for learning purposes but any other form will be accepted as well.

View 10 Replies View Related

Programming :: Read Multiple Arguments In Bash Script?

Nov 24, 2010

First, I made a simply script which let me download a file from a filehosting site on my server, but I can only put one link there, so I need help how to put multiple links in.Here is my script:

Code:
#!/bin/bash
echo "Enter URL:"

[code]...

View 3 Replies View Related

Programming :: (BASH) How To Read Multiple Lines From Text File

Mar 11, 2011

For example, I have a text file with data which lists numerical values from two separate individuals

Code:
Person A
100
200
300
400
500
600
700
800
900
1000
1100
1200

Person B
1200
1100
1000
900
800
700
600
500
400
300
200
100

How would I go about reading the values for each Person, then being able to perform mathematical equations for each Person (finding the sum for example)?

View 13 Replies View Related

Programming :: BASH - Create User And Password On Multiple Machines

Aug 9, 2010

I'm trying to write a script that will prompt the user for a username/password, then create that user/password in the right groups on all my machines. I know this is kind of a long way around to avoid a NIS server, but I like making my life more difficult.

This is what I have so far:

Code:

the script has 2 problems: The "if" functions return an error and do not compare the strings successfully. whatever password is entered does get applied properly and the user is unable to login

View 7 Replies View Related

Fedora :: Create A Form In Bash That Would Display Multiple Radio Lists?

Feb 4, 2010

I am attempting to create a form in bash that would display multiple radio lists with an OK and cancel button on the bottom. I tried using the command line tool dialog, which is really nice. But it won't let me do multiple radio lists on the same form.

View 2 Replies View Related

General :: Process Shows Multiple Process Ids(pids)?

Nov 9, 2010

I have a process running on Linux.When i do ps -eaf | grep <myProcess>, it show muliple entries for <myProcess> with different pids for each entry.Kindly tell me what could be the reason for a process having multiple pids?

View 1 Replies View Related

General :: Use 'iw' To Create Multiple Virtual Interfaces To Connect To Multiple Networks?

Oct 26, 2010

I'm trying to connect one computer to two others in an ad-hoc infrastructure.

[computer 1] ---- [computer 2] ---- [computer 3]

computer 2 is running Linux and has a single NIC wlan0. I want to it to connect to both computer 1 and computer 3 so each computer can talk to the other. No switch is available so it needs to be an ad-hoc setup.

[Code]...

View 1 Replies View Related

General :: Boot Up Process- The Read Only Rootfs Into VFS?

Mar 15, 2011

I've been reading various tutorials of the boot process but still am not clear. I don't care about grub stage 1 and 1.5 at the starting point of when the root filesystem is loaded into VFS(Virtualfilesystem), who is loading it, and from that point on. 1) Does grub load the root filesystem(read only) into VFS?2) Does the kernel load the root filesystem(read only) into VFS?3) Does INIT load the root filesystem(read only) into VFS?after this is concluded....Does INIT or the Kernel create the real root filesystem(rw)...right before the pivot.root

View 4 Replies View Related

General :: How To Run The Process On Multiple Core

Oct 26, 2009

How can we run the linux process like tar on multiple core? For example if we want to build the kernel we can use -j4 to distribute process of 4 different core. Is it possible to run long time consuming process on mulitple core?

View 1 Replies View Related

General :: Regarding Fork() Multiple Process?

Aug 2, 2011

trying to fork multiple child but the program does not go as i want...

My code :

Code:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

[code].....

View 14 Replies View Related

General :: Read A PID From A Text File And Kill The Corresponding Process?

Jun 26, 2010

I've got a command in a shell script:

Code:
php ./script.php > output.txt & echo $! > script.pid
This results in my script launching as a background process with output routed to

[code]...

View 3 Replies View Related

General :: Bash Script To Get PID Of A Specific Process?

Aug 23, 2010

I'm trying to write a script that involves storing a specific PID in a variable. I've got as far as: -

Code:
$PS_OUTPUT=ps -elf | grep <process name> | awk '{print $4}'
This stored the PID of the grep itself and the actual process I want. The output of

[code]...

View 6 Replies View Related

General :: Renaming Multiple Files In Batch Process

Feb 21, 2010

I have some random files in a folder. I want to rename all of the files in a batch process. I have a text file that contains the Currentname of all the files in the folder, as well as a text file with all of the Newname of files in the folder. I want to replace Currentnames with Newnames.

For example, here are the names of the files in the folder:
1.mp4
2.mp4
3.mp4

I have a text file with the Currentname of all the files in the folder:
1.mp4
2.mp4
3.mp4

I have a text file with the proper Newname of the file:
a.mp4
b.mp4
c.mp4

I want to rename Currentname with Newname in the folder. So when I go to the folder the Newname of the files are:
a.mp4
b.mp4
c.mp4

View 14 Replies View Related

General :: Bash Script To Read From MySQL?

Apr 20, 2009

I need a bash script that can read from a MySQL database field and insert the read information into a variable. I need it to read from a field in the database which will list if somone is using Linux or Windows. Once its done that the code will continue as follows:

Code:

if [ "$var" = "linux" ] ; then
OTHER CODE HERE
else

[code]....

View 1 Replies View Related

General :: How To Create And Call Process

Sep 24, 2010

I had an interview , where the interviewer asked me the question "How to create and call a process in unix". I answered that we can use the command
FORK()/ CLONE() to create a process.
But I didn't have the answer for the second question, how to call a process.

View 2 Replies View Related

Programming :: Bash Ctrl+c Tarp And Bash Read With Timeout?

Jan 24, 2010

simple bash code:

Code:
#!/bin/bash
trap "echo 'you got me'" SIGINT SIGTERM # to trap ctrl+c
echo "Press ctrl+c during 5 sec loop"
for ((i=0;i<5;i++)); do

[Code]...

How come code behaves normally and stops when ctrl+c signal is caught and resumes, but after I use at least one timeout read in the code it looks like, if signal is caught again it doesn't pause the execution but skips the loop. If you remove -t (timeout) option from the read, both loops look the same!

View 10 Replies View Related

General :: Bash Script - Read File Name With Two Digits?

Jun 20, 2011

I have many files with name in order of number. e.g)

u0101.asc
u0102.asc
u0103.asc

[code]...

I am trying to read file using for loop.

for ((date=01; date<=31; date++))
do
echo ${date}
done

but '01' is read(print) as '1' How can I make it read from '1' to '01'?

View 6 Replies View Related

General :: Bash Read All Environmental Variables Set By Other Shells?

Jul 23, 2010

For example, if I'm in csh, I can use `setenv VARNAME varVALUE` while I can use export in Bash. Given that the environmental variables are created, can BASH read env vars from csh and vice versa?

View 2 Replies View Related

General :: Bash Script - Check Process Is Running, If Not Start?

Feb 7, 2010

I am using Sphinx search on my webserver and it quits after a certain amount of time leaving my search page broken.Here is a bash script that I want to run every 10mins via cron:

Code:
#!/bin/bash
if pgrep searchd | grep "[0-9]"

[code]...

View 24 Replies View Related

General :: Create A C Program For An Orphan Process?

Jan 11, 2010

How to create a c program for an Orphan Process ?

View 5 Replies View Related

General :: Read From Input File And Append To Multiple Files?

Nov 22, 2010

I wanted to be as clear as possible. I have to add hundreds of new servers to hundreds of configuration files in Nagios. Here is a sample structure:

servers.txt has:
SERVER3
SERVER4

[code]....

View 10 Replies View Related

General :: Bash Script To Automate The Virtual Host Creation Process?

Mar 14, 2011

This is my sample code in /etc/httpd/conf.d/applications.conf file currently we are creating subdomain mannually for every new subdomain. I want to automate this process througs bash script , how its possible.

Code:

<VirtualHost *:80>
ServerName google.com
ServerAlias google.com

[code]....

In this code which i marked BOLD that content only we'l change for every subdomain. while manually doing this most of the times errors are coming to avoid that i need to automate this process.

View 3 Replies View Related

General :: Motion Run Error - Cannot Create Process ID File

Jun 7, 2011

Code:
root@sok-HP-ProBook-4520s:/usr/local/etc# motion
[0] Processing thread 0 - config file /usr/local/etc/motion.conf
[0] Motion 3.2.12 Started
[0] Motion going to daemon mode
[0] Exit motion, cannot create process id file (pid file) /var/run/motion/motion.pid:

View 4 Replies View Related

General :: Bash Script That Read From File And Ping Remote Host

Feb 13, 2011

Q=What will this do?
A=This will read from /root/Desktop/iplist (or anywhere you want to put the list) after it reads the ip it will ping the ip two times. If the remote host is up then it will write the ip to a log. If the ping fails it will display it on the screen, write the ip to syslog so that you can do remote logging, and last it will send the ip by email to a user or a group of users.

Code:
#!/bin/bash
#wrote by Zach Underwood feb-12-2011
#test and wrote on centos 5.5 with sendmail
rm -f /root/Desktop/iplog #This will remove the good iplog
exec 9</root/Desktop/iplist #put full path the file where ip list is. Make sure that the ips are listed one per line.
while read -u9 ip
do
ping -c 2 $ip > /dev/null 2> /dev/null # ping and discard output
if [ $? -eq 0 ]; then # check the exit code
echo "$ip is up" >> /root/Desktop/iplog #write the ip of the hosts that are up
else
echo "$ip is down" # will show on the screen the ips that are not up
logger -p auth.notice "$ip is down" # will write the down host to syslog
echo "$ip is down" | mail -v -s alert user@anydomain.com > /dev/null 2> /dev/null #will send mail users about host down
fi
done

View 3 Replies View Related

General :: Read A Text File And Ftp Files Using Bash W/out Leaving The Ftp Prompt

Oct 9, 2009

I have a script almost working except for 1 thing. What I'm trying to do is read a file that has the files that need to be FTP'd using a bash script. I have everything working except the reading of the file. It works outside of the ftp script I've wrote but once I put it in the FTP script it doesn't.

Here's the Script:

#Here's where the problem is that I know of

I've been playing w/ the exclamation points to see if that could be the problem, but so far no luck.

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved