Ubuntu :: Loop Commands In Bash Scripting?

May 15, 2010

What is the difference between For and While when creating loops in bash scripting?

View 1 Replies


ADVERTISEMENT

Programming :: Shell Scripting Loop Error Yal2361: Command Not Found?

Jul 22, 2011

I have written the following script in my linux server to add users for LDAP database.But i can't able to run this.

The script is as following

#!/bin/bash
echo "Mention the username which you want to convert LDIF format"
read username
if ["$username" -e "/ldiffile/passwd"]; then
echo "Username already exists"
else
cat /etc/passwd | grep -i "$username" >> /ldiffile/passwd
fi
The output which i got :
. ldapadd.sh
Mention the username which you want to convert LDIF format
yal2361
-bash: [yal2361: command not found

please let me know where need to change and what

View 5 Replies View Related

Programming :: Reading A Bash Variable In Bash Scripting ?

Nov 26, 2008

I have a config file that contains:

my.config:

Code:

Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.

Here is my parse_cmd script:

Code:

View 3 Replies View Related

Ubuntu :: Loop Through Subfolders And Execute Commands Or Scripts?

Apr 3, 2010

Let's say I have 4 subfolders in the folder test as shown below:

drwxr-xr-x 2 muskedear muskedear 4096 2010-04-03 17:11 sub001_p1
drwxr-xr-x 2 muskedear muskedear 4096 2010-04-03 15:38 sub002_p1
drwxr-xr-x 2 muskedear muskedear 4096 2010-04-03 15:38 sub001_p2
drwxr-xr-x 2 muskedear muskedear 4096 2010-04-03 15:38 sub002_p2

I want to loop through the folders and check if they end with *_p1 or *p2. If a given folder ends with *p1, I want to cd to that folder and manipulate certain files in that folder. If the folder ends with *p2, I want to perform different manipulations on certain files.

View 1 Replies View Related

General :: Running Bash But Common Bash Commands Not Working?

Jul 17, 2010

below are the details of my system. I have bash as my current shell, some really common commands aren't working.

Do I need to do a re-installation of bash? Or how do I install a selection of bash commands which I need? (for example a subset of [URL])

Code:
root@sdptfw:~ # uname -a
Linux sdptfw.sdpt.co.za 2.4.36 #1 Tue Jul 22 13:13:24 GMT 2008 i686 i686 i386 GNU/Linux
root@sdptfw:~ # echo $SHELL$
/bin/bash$

[Code]....

View 13 Replies View Related

Server :: Script Running Ssh Commands (via Loop) Exiting After First Iteration?

Oct 24, 2010

One of my servers needs to issue an "apt-get update" command on each of the clients in a lab. However, after the first update, it exits. In trying to replicate the problem with a simpler script, I created the following which fetches the listings of multiple directories from a client:

NUM=0
cat paths | while read DIR; do
ssh server-name ls $DIR > /tmp/$NUM.txt
NUM=`expr $NUM + 1`
done

Again, after the first iteration, the script exists. I tried the following line too, but it made no difference:

bash -c ssh server-name ls $DIR > /tmp/$NUM.txt

The only thing that worked so far is this

xterm -e ssh server-name ls $DIR > /tmp/$NUM.txt

View 3 Replies View Related

Ubuntu :: Bash Scripting Gives Bad Substitution

Feb 18, 2011

I'm trying to get the substring of a string in bash. Here is the code:
Code:
#! /bin/bash
LOCAL_HOSTNAME=$(hostname)
echo $LOCAL_HOSTNAME
INDEX_OF=`expr index "$LOCAL_HOSTNAME" 1`
echo $INDEX_OF
SERVER_HOSTNAME=${LOCAL_HOSTNAME:0:INDEX_OF}
echo $SERVER_HOSTNAME

It's supposed to get the current hostname, assign it to variable LOCAL_HOSTNAME, get the first occurrence of "1" from hostname and assign value to INDEX_OF, the get the substring from variable LOCAL_HOSTNAME (starting at index 0 through INDEX_OF) and asign it to SERVER_HOSTNAME. No matter how much I've tried it keeps throwing Bad substitution error at the substring. I've searched and it says it has to be bash... but it is bash, both the sh script and the running shell. The LOCAL_HOSTNAME and INDEX_OF variables are ok.

Here is the output:
I've also tried to get the substring without the INDEX_OF but it gives the same error: SERVER_HOSTNAME=${LOCAL_HOSTNAME:0}
Code:
host1
5
test.sh: 7: Bad substitution

View 2 Replies View Related

Ubuntu :: Image Manipulation In Bash Scripting?

Jul 5, 2010

I have a bash script that inserts some text onto every image at a certain place within a directory.

Heres what I have (from a German friend who appears online once in a blue moon), this is the line that resizes to a maximum of 800 either width or height and puts in the text 'text goes here'.

convert ${bild} -resize "800x800>" -strip -family Arial -pointsize 16 -draw "gravity southeast fill rgba(255,0,0, 1.0) text 10,10 'text goes here'" ${dstdir}/${bild}

Now, I would like to know how to place a PNG image (a watermark, so to speak) over all images within a directory in a certain place, so how would I go about modifying this line to place an image instead of the text?

View 9 Replies View Related

General :: What Is Purpose Of Bash Scripting?

May 15, 2010

What is the purpose of bash scripting? Is it just for file manipulation?

View 4 Replies View Related

Programming :: Scripting The Email With Bash?

Jul 8, 2010

I need to find a way to download the attachment from a daily report e-mail to me. The kicker is it will need to be down with a cron tabbed bash script.For example, which linux based CLI client is best suited to be scripted?

View 2 Replies View Related

General :: How To Set Incrontab In Bash Scripting

Mar 7, 2011

I have a question;

Is it possible to set incrontab in bash script? I tried to set normal crontab and it works like a charm but unfortunately not "incrontab"

I have two bash files; test-incrontab.sh and addlinetocrontab.sh and here are the contents of these files respectively;

Code:

Code:

As you can see there are two enteries in each file. One for normal crontab and other one for incrontab. When i run "test-incrontab.sh" like following;

Code:

crontab works perfectly and i can see cron job set but for incrontab it just does not work. No error either!

I am only getting this back "table unchanged"

View 2 Replies View Related

Programming :: Bash Scripting: How To Keep Leading 0 On ' And '

Jan 27, 2010

I'm trying to put together a script that will quickly run through an archive directory of log files that are named by day of the month 01.gz, 02.gz, 03.gz.... 31.gz. The script uses gunzip -c | grep | wc to count up the total number of hourly occurrences of a filename and outputs the results to stdout.

The only snag I have left is the octal limit when it gets to 08 and 09. I've seen examples using perl and awk, but this script uses a number of nested for loops and if statements that I don't want to have to rewrite in a different syntax. I found that I can use num=10#08 to set that variable to a base 10 instead of a base 8, but then I lose the leading 0 again when it passes the number to the next filename variable.

View 8 Replies View Related

Ubuntu :: Bash Scripting: Making A Text File

Jul 12, 2010

I am tying to write a script that asks for user input and saves it to a text file using awk so example #!/bin/bash read a awk #saves to file

I had a working scripted last night, deleted it by mistake and for the life of me can not remember how i did it.

View 2 Replies View Related

Ubuntu :: Bash Scripting - To Copy A List Of Files

Dec 6, 2010

I'm writing a bash script to copy a list of files and do some stuff to them. Basically, I have the code written that does what it needs to do, but I can't quite understand why it works. I was hoping someone could clear up my understanding a bit.

Code:

The first line generates a list of files. I wrap each line in quotes because they usually have spaces in the directory names.

The second line changes IFS, and I understand what IFS itself does. What I don't quite get is what the separator becomes with that echo statement. If I'm reading that correctly, the backspace will remove the newline and essentially the result is nothing? I found this solution on a web page somewhere, but it was years old and there was no real explanation.

View 1 Replies View Related

Fedora :: Bash: While Loop Will Not End

Jan 9, 2010

This gives a selection menu where you choose an option, and it should continue. I have several of these as part of a much larger script, but something is wrong with this while loop.

Code:
VARIABLEINPUT="1"
if [ $VARIABLEINPUT == "1" ] ; then
echo -e "${YELLOW}How often would you like the automatic update and maintenance to occur after the installation?:
${RED}1)${WHITE} Hourly
${RED}2)${WHITE} Daily
${RED}3)${WHITE} Weekly
${RED}4)${WHITE} Monthly
"
[Code].....

A very simple loop that uses a variable from earlier in the script to adjust variables for later in the script. For some reason, this while loop will not end - I've noted where with echos.

View 4 Replies View Related

Security :: Bash: Can't Su Within While Loop

Jul 18, 2010

I have a while loop in a file that looks like:

Code:

while IFS=":" read name script
do
su
exit

[code]....

Where I redirect the file into the loop, for some reason, I can't do an su when I redirect a file like that. I get the error, "su: must be run from a terminal." Why is this? How can I fix it?

View 7 Replies View Related

Ubuntu :: Bash Menu Option Loop

Mar 19, 2010

I am trying to make a bash menu that loops with options but it does not work as I want:

Code:

I want to make it read an option and do the action then return to menu.

View 2 Replies View Related

Debian Programming :: Bash Scripting For Jessie

Aug 25, 2015

You are probably using systemd (check it with ps --pid 1) and therefore /etc/init.d isn't considered for autostart. Here can you find some information about systemd and autostart [1]. As far as I know systemd isn't intended to start applications with systemd. I recommend you to use the autostart feature of your window manager or desktop environment or at least the .xinitrc.

[URL] ....

View 7 Replies View Related

General :: Bash Scripting - Grab First And Last Number?

Jan 13, 2011

I'm trying to get an output of a file in numeric order. Basically I need the starting number and the ending number in sed this into anther file. The test2.lis file I'm just awk'ing for the first row and if its out of order put it in order so I can grab the first and last numbers. I'm sure I can do this all in an array. The first sed command gets rid of blank lines and outputs it to a file. Then I head and tail for the first and last number then I want to sed those numbers into a file that exsist.

[code]...

The error I get is:

sed: -e expression #1, char 24: unterminated `s' command.

View 13 Replies View Related

General :: Bash Scripting / A Command That Can Stop Others?

Mar 31, 2010

i would like to ask something very simple i hope for most off you but i couldn't find anything in other questions so specific...

So...i need a command to stop another command.

more specific i have to run airodump-ng and i want this command to stop after some seconds (or minutes) automatically....

View 6 Replies View Related

General :: Combine Bash Scripting With Apache?

Apr 3, 2011

how to combine bash scripting with apache.

View 5 Replies View Related

General :: Bash Shell Scripting Request?

Feb 27, 2011

I am working on a simple script that should take two command line arguments, a [number] and a [name]. The first thing the script should do is check to make sure that no more and no less than two command line arguments have been entered when calling the script - an error message should be delivered if the condition is not true.

If two args have been entered, then the message 'processing "scriptname"' should appear, where scriptname is the name of the script being called. The script should then write to the screen "Hi [name]!", and should write this phrase [number] of times. For example, the command $ myscript 2 joe would produce the output: I have read the manual many times looking for examples, and I am very close by virtue of my own efforts. Further, I have searched these forums and others for good examples, which have also gotten me very close. Still my script is not completing the objective, and I am wondering if someone could point me in the right direction. Script:

[Code]...

View 13 Replies View Related

Software :: Bash Scripting And Integer Variables?

Jun 6, 2010

Are there numerical variables (like type int in C) in the shell script language of bash? Say I want a counter to increment each time a loop is traversed.

View 1 Replies View Related

Programming :: BASH Scripting - Creating A Map Tree?

May 7, 2011

looking to write a dependency map tree that creates a tree structure of object names . This tree will be written to a file and read back to create the tree structure of files . how to write this using bash ?

View 1 Replies View Related

Programming :: Bash Scripting: Menu From File?

May 29, 2011

I have a file called list.txt with on word on each line that changes in length. I'd like to make a menu, each line being its own choice. I pieced together most of it the only thing missing is a failsafe for typing a number out of range

Code:
#!/bin/bash
p=`cat list.txt | awk '{print$1}'`

[code]....

View 2 Replies View Related

Programming :: Bash Scripting - Pointed In The Right Direction?

Jul 6, 2011

I've been using Ubuntu for about 6 months now, but haven't had a need to start scripting until just recently. I know programming basics, but that's about it.Anyway, I have a program that I would normally run in this manner (note that I didn't create a permanent alias because I've been moving the program around a lot):alias dx='python /path/to/dxProgram.py' dx A_input.dx B_input.dxSo, you see, program dx takes two input files, and 'A' must come before 'B'. I have a folder full of these types of files that I'd like to loop through with this program. They're named as follows:

0_A_input.dx
0_B_input.dx
1_A_input.dx

[code]....

View 6 Replies View Related

Ubuntu :: Adding Strings To The Front And End Of Variables In Bash Scripting?

Mar 3, 2010

How do you add strings to the front and end of variables in bash scripting? for example, if I have

Code:

in as the contents of my variable, I want to add "l" to the front and "k" to the back of the contents.

View 1 Replies View Related

Ubuntu :: Start Learning GUI Bash Scripting But Can't Find The Right Tutorial?

Sep 30, 2010

I want to start learning GUI bash scripting but I can't find the right tutorial. I'm interesting at creating menus like ex. IPTRAF or MC (midnight commander) but all i find is tutorials for KDE & GNOME. The idea is that I want to create programs that don't need X sessions.

View 2 Replies View Related

General :: Bash For Loop Not Working?

Apr 21, 2010

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

View 5 Replies View Related

Ubuntu :: Bash Script - For Loop - Replacing Strings?

Aug 16, 2011

I'm not overly great with bash scripting. I do more batch file stuff for Windows than anything else but I'm trying to branch out a bit. (Frankly, I'd love to do this in Ruby but I'm not there yet...) Maybe I'm not using the correct terminology and that's why my searches are coming up useless...

Anyway, I have a script that does some work with HandBrake. Although it deals with HandBrake, I think the issue is not with HandBrake itself. The issue: I had a simpler script which worked fine but it would give me an MP4 with a file name of: Some Movie Name.iso.mp4 and it would still play but I wanted to get rid of the .iso in the file name. I also wanted to drop it into another directory during the encoding. That's why you see a $source & a $destination variable.

handbrake.sh
Code:
#!/bin/bash
source=/media/data/movies
destination=/media/data/movies/mp4s

[Code]...

View 7 Replies View Related







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