Programming :: Shell Scripting Array - Bad Substitution

Jun 19, 2009

I made a little rsync script for log transfer.

Code:
SERVERS=(SERVER1 SERVER2 SERVER3)
SERVER1_SERV=(web ftp mail)
SERVER2_SERV=(web transcoding)
SERVER3_SERV=(web ftp mail)
for SERVER in ${SERVERS[@]}
do
echo "Starting tranfer for server $SERVER"
for SERVICE in ${$SERVER_$SERVICE[@]}
do
something_to_be_done
fi
done
But when I run it I get ${$SERVER_$SERVICE[@]}: bad substitution

View 5 Replies


ADVERTISEMENT

General :: Incrementing Array Element In Shell Scripting

Jun 23, 2010

ch[1]=0; ch[2]=0; ch[3]=0; ch[4]=0; ch[5]=0; ch[6]=0; ch[7]=0; ch[8]=0; ch[9]=0; ch[10]=0;ch[11]=0; ch[12]=0; ch[13]=0; ch[14]=0; ch[15]=0 ch[16]=0; ch[17]=0; ch[18]=0; ch[19]=10; ch[20]=0;

I have an array ch and I want to increment each element in my array for the following if statement. I'm not sure I have the right array increment syntax but I have tried it in different ways ant it doesn't seem to work.

I tried ch[$1]++, ch[$1]+1, ch[$1++], ch[$1]+=1, ch[$1]=ch[$1]+1 none of these seem to work.
# while loop reading from read.txt for check list 1 - 15
for i in `seq 15`
do
a=`grep "${cl[$i]}" $file`
status=$?
if [[ $status = 0 ]];
then
echo -n -e "1 "
let ch[$i+1]
let k++
else
echo -n -e "0 "
fi
done
for l in `seq 20`
do
echo -n -e "${ch[$l]} "
done

View 2 Replies View Related

Programming :: Shell Scripting / Create A Shell Script Similar To Ls?

Jun 5, 2011

I am trying to create a shell script similar to ls, but which only lists directories. I have the first half working (no argument version), but trying to make it accept an argument, I am failing. My logic is sound I think, but I'm missing something on the syntax.

Code:
if [ $# -eq 0 ] ; then
d=`pwd`
for i in * ; do
if test -d $d/$i ; then
echo "$i:"
code....

View 10 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

Programming :: Shell Scripting: How To Create A User

Sep 5, 2010

How do I create a user account in a shell script? I know this may sound n00bish to you, but I know it's more than just mkdir-ing the home directory and subdirectories.

View 7 Replies View Related

Programming :: Convert String Into An Integre In Shell Scripting?

Dec 2, 2010

I need to part a string into separate integers ....like "0x0-0xffffffff,0x20000" into 3 integers 0x0 and 0xfffffff and 0x20000.... i can't use any other high-level languages ..

View 3 Replies View Related

Programming :: CGI Shell Scripting : Possible To Call Function From Other Script?

Mar 15, 2011

I got two cgi shell scripting files. Is it possible when i am in file 1, to call a function from file 2?

View 2 Replies View Related

Programming :: Compare Two Files Using Perl Or Shell Scripting?

Mar 8, 2010

I want to compare the following two tab-delimited .txt files (both were subsets of the original files) by comparing Columns 3 and 4 simultaneously. It is easy to compare C3 because both C3s are just numbers. But how to compare C4s?Basically, in File1, "G,G" = G in File2, "C,C" = C in File2, "A,A" = A in File2, "T,T"= T in File2.In File2, A/T in Column4 just equals "A,T" or "T,A" in Column4 of File1. C/T in Column4 just equals "C,T" or "T,C" in Column4 of File1, and etc.

File1:

C1C2 C3C4
ih509rs12345467244750"G,G"
ih499rs6049687244911"C,C"
ih508- 7244977"A,A"

[code]....

View 2 Replies View Related

Programming :: Ignore Case In If Statement Shell Scripting

Feb 3, 2010

How do i make my strings case-insensitive while comparing them with an if statement?

View 2 Replies View Related

Programming :: QNX Checksum Call In Cgi Shell Scripting Not Working?

Mar 11, 2011

I have a QNX machine with a slinger webserver running on it. With a cgi script i'm trying to do the QNX cksum call and compare it's output value with a fixed output. When i execute the script at the command line it works perfect, but when execute this script by by the webserver in my browser it doesn't work. Here's my code:

#!/bin/sh
FILE="/home/checkfile"
ORIGCHECK="1712885500"

[code].....

Could it be possible that i'm not allowed to do the cksum call in combination with the slinger webserver?

View 4 Replies View Related

Programming :: Shell Scripting: Scraping Public IP And Emailing?

Jul 3, 2011

so I wrote a simple script to scrape whatsmyip.org for my public IP address and then email it to me if it has changed. I set this up as a cron job ever 30mins.the problem is, it works for about 18 hours and then will have an issue where it says "line 33: [: too many arguments" Which line 33 happens to be my if statement. Now like I said it works fine for about 18 hours, i run the script with 2>&1 to a .out file so i can see what its doing...this is the output of the .out file, the "xxx" does actually show the ip.."PHP Code:

xxx.xxx.xxx.xxx
already in file
xxx.xxx.xxx.xxx

[code]....

View 14 Replies View Related

Programming :: C-shell Scripting Syntax Error When Defining Two Variables A1 And A2

Apr 5, 2011

I am trying to modify a script for research purposes and am having difficulty here as I have little prior experience with C-shell scripting.

The script looks as follows (it includes tcl commands like runFEP that you can ignore)

#!/bin/bash

for ((old=1, new=2; old<=4; old++,new++))
a1=${old}%50
a2=${new}%50
do
cat > input${new}.conf <<EOF
${a1}
code....

My question: I keep getting a syntax error when defining my two variables a1 and a2. I essentially need these variables to be
a1 = value of variable old divided by 50
a2 = value of variable new divided by 50

View 1 Replies View Related

Programming :: NSH Shell Scripting \ The Value For The Vatriable Would Be Coming From A File With Three Columns?

Jun 24, 2011

I'm writing a script and I have doubts on how to assign values to an already established variable. The value for the vatriable would be coming from a file with three columns. I'm using the awk command for this. Am I doing it correctly? which of the following two ways is the better one or if both are wrong which one should I use?

#!/bin/nsh
inputfile=$1
rolename=$2

[code]....

View 2 Replies View Related

Programming :: Shell Scripting For Accepting Input From Different Directories Automatically

Nov 6, 2010

The two shell scripts (t1prog and t2prog) are given below they are working fine. The input for the first program is 't1.det' and for second program is 't1.rnaml'. These two input files are in 'dir1' folder. I am executing the shell like 'sh t1prog > t1out' and 'sh t2prog > t2out' from this directory only. Then I am executing a java program 'java RNA'; for this, t1out and t2out are input files used in the program and I am getting the final output on screen.

The input files 't1.det' and 't1.rnaml' are in different folders with same name and with different values. Each folder specifies one gene sequence input files.

In mfold directory there are 5 directors and each directory contains these input files as shown below
cd mfold
dir1 dir2 dir3 dir4 dir5
cd dir1
t1.det t1.rnaml

[Code].....

for inputs in different directories and executing these and redirecting the final ouput after executing 'java RNA' statement to a file is needed.

View 2 Replies View Related

Programming :: Shell Scripting - Value Disappears Depending On Argument Order

Mar 21, 2011

Examples:
Code:
$ ./test.sh -a -c 2
operator is -gt
remcount is
^ value missing!

Code:
$ ./test.sh -b -c 2
operator is -lt
remcount is
^ value missing!

Yet when "-c" is the first argument, its value is present:
Code:
$ ./test.sh -c 2 -b
operator is -lt
remcount is 2
What could I do to ensure the value of "-c" is picked up regardless of the argument order?

View 5 Replies View Related

Programming :: Shell Scripting: Trying To Combine Upload And Download Totals From Txt File By Ip Add

Sep 6, 2010

I have two files, uploads.txt and downloads.txt. I would like to combine the columns of these files based on the ip address. How can I best do this?

Uploads.txt Code: 192.168.0.147 1565369
192.168.0.13 1664855
192.168.0.6 1332868 Downloads.txt Code: 192.168.0.147 9838820

[code]...

View 7 Replies View Related

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 :: Finding Maximum Length File In A Directory Recursively Using Shell Scripting?

Nov 8, 2010

I want to find maximum length file in a given directory. It should search recursivley. I want this to be done using ls and simple looping constructs.

View 6 Replies View Related

Programming :: Irregular 2D Array In Shell Script

Aug 16, 2010

I am trying to create a shell script to automate a process that takes inputs from two sets of data. The variable SHELL in my system echoes as /bin/tcsh, but I see that my /bin directory has other possibilities, such as bash. So, if changing the shell could simplify my problem, then I would go with that.

I have a list of files containing data about objects, say
obj1.dat, obj2.dat, .... objn.dat, where n is around 20 (it varies).
These objects belong to a few different categories, and there are files detailing the properties of the categories, say
cat1.prop, cat2.prop, ... catm.prop, where m is smaller than n (more than one object in each category).

I know that shell scripts can handle 2-d arrays, although I am not sure how. The thing here is that category 1 could have 5 objects and category 3 could have 7 objects. So, this could produce a 2-d array, but not a rectangular one. I need to process these files taking into acount the data about the object and the properties of the category the object belongs to. Here is what I tried to do:

# First I enter a list of category names and m lists of objects in each category
category='cat1 cat2 cat3 ... catm'
cat1-obj='obj1 obj2 obj3'
cat2-obj='obj4 obj5'
cat3-obj='obj6 obj7 obj8 obj9 obj10'
.
.
.
catm-obj='objx objy objz objn'

# The lines above show the irregular 2-d array. Then I try to trick the script into parsing through this irregular 2-d array:
for i in $category
do
data='$i -obj'
for j in $data
do
mycommand $j.dat $i.prop > $j-$i.out
done
done

The line "mycommand $j.dat ..." is just the line that processes the information. That has been tested to work fine. Feeding the information to this is what does not work. The lines " data='$i-obj' " and " for j in $data " do not have the desired effect. I have tried other ways, like data=`echo $i "-obj"` and things of the sort, by to no avail.

View 1 Replies View Related

Programming :: Creating Array In Shell Script

Feb 7, 2011

1. How do I create an array with 5 entries
2. Output one of the entries in the array randomly
3. Subtract the entry output from the array
4. Repeat steps 2 and 3 until there are no more entries in the array

View 11 Replies View Related

Programming :: Array In Shell Script - Code Not Working

Oct 16, 2010

I am passing an array in function. I want to read the first content again and again until it is empty so

function calltoarray
{
read $1[0]
while [ ! -n "$1[0]" ]
do
echo empty
read $1[0]
done
}

But the code is not working. If we just press enter without value at read $1[0]. It do not get into while loop.

View 2 Replies View Related

Programming :: Creating Array From Command Output (Bash Shell Script)

Jan 26, 2011

I have a command that outputs n lines of text, and I want to place each line into an array element, but I can't seem to get the syntax correct

So my command is this:
cat $configfile | sed -n '/cluster:'$clustername'/,/cluster/ p' | awk /host/

Which produces many lines depending on the value of $clustername. I'd like to get each line as elements of an array.

View 5 Replies View Related

Programming :: Writing Shell Snip To Import CSV Data Into Bash Array

Jan 5, 2011

I have been trying to write a simple snip of bash shell code to import from 1 to 100 records into a Bash array.

I have a CSV file that is structured like:
record1,item1,item2,item3,item4
record2,item1,item2,item3,item4
record3,item1,item2,item3,item4
record4,item1,item2,item3,item4

And would like to get this data into corresponding arrays as such:
$record1[item1-4]
$record2[item1-4]
$record3[item1-4]
$record4[item1-4]

View 9 Replies View Related

General :: Shell Script For Substitution?

Jul 9, 2011

So, I have 100 folders each of them include a file called script.txt and script2.txt. the file script.txt has and 100include files that have the same name like the folders. So, for example if I have the folders A, B and C then the script.txt will include 3lines such as:

*include A
*include B
*include C

I want for each folder (A, B and C) to create script2.txt which will substitute *include A with $include A, respectively for each folder.

so for folder A, I will have script2.txt

$include A
*include B
*include C

[Code].....

but it is substituting "*" with "$" in each file for all the lines. I think i should probably close earlier a loop.

View 4 Replies View Related

Software :: Export A Variable To Parent Shell In Shell Scripting?

May 21, 2009

Is there a way to export a variable to parent shell in shell scripting ?

View 3 Replies View Related

Programming :: Bash Shell Scripting / Using The Sort Command To Sort The Top 5 CPU Processes?

Feb 28, 2010

What options should I use when I'm using the sort command to sort the top 5 CPU processes (ps -eo user,pid,ppid,%cpu,%mem,fname | sort ??? | head -5) showing max to min usage?

View 2 Replies View Related

General :: Shell Script -- Awk Variable Substitution?

Oct 7, 2010

I have a script in which I'm reading a file line by line and I'm finding certain position value using awk index as

Code:
# 2 spaces before open parens
pos=`echo | awk -v Line="$Line" '{ print index("'"$Line"'"," (")}'`

[code]....

View 2 Replies View Related

General :: Bash Scripting - Executes A Few Perl Scripts - Create A New Array And Take The Hostname

Apr 4, 2011

I'm writing a bash script that executes a few perl scripts. One of the perl scripts that I need to execute requires two arguments with it. The arguments are stored in a txt file, each line contains a hostname and its corresponding IP address separated by a ":" (colon), the txt file looks like this below:

[Code]...

I'm not sure if it's the best way to accomplish this but here it goes. In the bash file, let's call it getHosts.sh, I create an array and assign each line of the file to an element in that array. I then think I need to create a new array where I take the hostname (which is before the ":") separate it from its IP address and place the IP address on a new line just below the hostname (this way I can reference to it like $hostNames[$x] would be the hostname, and $hostNames[$x+1] would be its IP address). So the new array would now look like this below:

[Code]...

View 4 Replies View Related

Ubuntu :: Sed And Shell Scripting ?

Feb 22, 2010

I have recently put together an install script to make my life a little easier.

The server is using lighttpd and I wish for the auth mod to be enabled.

For the line:

I require the script to call the servers external IP and insert it in place of 127.0.0.1

View 5 Replies View Related

General :: What Is Shell Scripting?

Feb 15, 2011

What is shell scripting? what is 'bash'?

View 14 Replies View Related







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