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


ADVERTISEMENT

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 :: 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 :: 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 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 :: 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

Programming :: Creating Script For Mysql Connection From Shell?

Jul 8, 2011

I'm creating script to connect to mysql and perform function. I'm into process in querying mysql from shell. Here is the content of a sample script:

Code:
#!/bin/bash
USER=scripter
PASS=test123
DB=test_scripts

View 2 Replies View Related

Programming :: C Realloc Resize Array / Delete And Add Information Into The Array?

Mar 6, 2011

I am trying to dynamically delete and add information into the array "blah"

Code:
int blahsize = 1;
char** blah = (char**) calloc(blahsize+1,sizeof(char*));
Adding information:
Code:
blah[1]=stuff1;
blah[2]=stuff2;
code....

View 2 Replies View Related

Programming :: Convert Short Array To Char Array?

Jun 7, 2010

I have trouble converting a short array to a char array

Code:

short pShort[4] = { 0x41, 0x42, 0x43, 0x44 };

How to convert this to a char array?

View 4 Replies View Related

Programming :: Converting A PHP Array Into An HTML Array?

Aug 9, 2009

I'm writing a PHP program. I've encountered a problem; in the following code I try to pass $_POST['delete'] which is an array as the value of a hidden input to some form, but it doesn't do so.there's something wrong with converting PHP array into HTML array. I'm sure that $_POST['delete'] is not null and is a real array.

echo '<input type="hidden" name="delete[]" value="'.$_POST['delete'].'" />';

View 4 Replies View Related

Software :: Creating New Mdadm Raid 1 Array?

Mar 2, 2011

a server that was running a hardware isw raid on the system (root) disk. This was working just fine until I started getting sector errors on one of the disks. So, I shutdown the system and removed the failing drive and installed a new drive (same size). On reboot I went in to the intel raid setup and it did show the new drive and I was able to set it to rebuild the raid. So, continuing the reboot everything came up just fine except the raid 1 on the system disk. I have tried many times to get the system to rebuild the raid using dmraid, but to no avail it would not start a rebuild. In order to get the system back up and make sure that the disk was duplicated I was able to 'dd' the working disk to the new disk that was installed.At present when I look at the system it does not show up with a raid setup on the system disk ( this comprises the entire 1TB disk with w partitions sda1 as / and sda2 as swap).Problem:I have decided to forego the intel raid and just use mdadm. I have a test system setup to duplicate (not the software, but the disk partitions) the server setup.

Code:
[root@kilchis etc]# fdisk -l
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

View 12 Replies View Related

Programming :: Filling 2D Array With 1D Array In C?

May 26, 2010

(I am using vector() and matrix() functions from "Numerical recipes in C".)There are 100 numbers to be stored in 2D array of 10 rows and 10 columns.100 numbers are stored in a 1D array.I get "segmentation fault" at the line indicated in the segment of my code below:

Code:

:
:
#define size 100
#define nl 1

[code]....

View 12 Replies View Related

Server :: Creating Backup Disk Image Of RAID 1 Array (MDADM)?

Oct 27, 2010

We have some servers that run in very harsh environments (research vessel) that need to have high-availability.We have software RAID 1 for some measure of resiliency, along with proper data backups (tapes etc), however we would like to be able to break out a new server and re-image it (including RAID setup) from a known good copy if the hardware completely fails on the production box. Simplicity of the process is a big plus.I am interested in any advice on the best way to approach this. My current approach (relatively new to Linux administration, totally new to MDADM) is to use DD to take a complete gzipped copy of one of the RAID'ed devices (from a live CD): ode:
dd if=/dev/sda bs=4096 | gzip -c > /mnt/external/image/test.img then reverse the process on the new PC, finally using Code:mdadm --assemble to re-create and re-build the array.

View 1 Replies View Related

Programming :: Bash Array Add Function Example Using Indirect Array Reference As Function Argument?

Jun 20, 2010

I looked on the net for such function or example and didin't find anything, thus after having made one i guess it would be legitimate to drop it to see what others thinks of it.

#!/bin/bash
addelementtoarray()
{
local arrayname=$1

[code]....

View 10 Replies View Related

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

Debian :: Creating A Bash-shell Script

Dec 1, 2015

how to do in Debian

1. am required to create a bash-shell script called terminator that terminates all processes of a name given to the shell script as an argument. Make sure the terminator shell script will not take any crucial file system services as arguments.

2. Show how you would configure an Ethernet card by reapplying your existing IP and network mask

3. Install a workable nfs file sharing system between your system and a remote system, using optimum values for resize and wsize.To demonstrate send a 512Mb block of random data between client and server using the dd command.Write down the relevant steps and procedures

View 6 Replies View Related

General :: Creating A Shell Using C Which Could Implement LS Command

Sep 4, 2010

I would like to create the shell which would support the LS command in C++. And the way the command prompt can be changed.

View 7 Replies View Related

General :: Creating Tar : Shell Vs Ui, Size Differs?

Oct 14, 2010

In a shell script, I am creating a .tar using this command

Code:
tar -zcvf dst/lib/library.tar.gz dst/lib
There are two problems:

[code]...

View 1 Replies View Related

Software :: Shell Script For Creating Report?

Aug 31, 2010

`cat /var/log/secure | grep "refused connect" |awk '{print $9}'|sed 's/::ffff://g'|uniq -c | sort -nr |head -2 | awk '{print $2}' >/root/sample`
for IP in `cat /root/sample`;

[code]...

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

Programming :: Arrays In The C Programming Language Are Pointers To The First Element Of The Array?

Mar 27, 2010

I wonder why arrays in the C programming language are pointers to the first element of the array, not the first element of the array itself?

View 14 Replies View Related

Ubuntu Multimedia :: Creating Parnoramic Pictures Using The Shell With No Gui?

Mar 23, 2010

I know that it's possible to create panoramic photos very easily with hugin. But I would like to create a script for nautilus where I select my picture and then create a panoramic without any questions.I guess it's possible but I can't find on google, each time I find something about hugin.Is it possible to call from the command line and hide the interface during the process ?

View 3 Replies View Related

General :: Source Code Or The Procedure For Creating Own Shell?

Nov 3, 2010

i need the source code to create my own shell in linux or provide atleast procedure for doing it

View 9 Replies View Related

Server :: Creating Samba User Using Shell Script?

Apr 8, 2011

how to create Samba user using shell script

View 6 Replies View Related

Programming :: Bash-shell-like Less Functionality In The Python Shell?

Jun 25, 2010

Is there some type of functional way to read things in the Python shell interpreter similar to less or more in the bash (and other) command line shells?

Example:

Code:

>>> import subprocess
>>> help(subprocess)
...
[pages of stuff to read]
...

I'm hoping so as I hate scrolling and love how less works with simple keystrokes for page-up/page-down/searching etc.

View 4 Replies View Related

Ubuntu :: Creating Shell Script From Source Code For Cron?

Jan 31, 2010

This is regarding the KDE application Basket:

I want to create a shell script that I can run as a cron job to do automated backups. how to proceed. I have the source code and have pulled out the backup source files. Here is the link for the source code. The download is at the bottom of this page. The backup files can be found in the src folder listed as backup.cpp and backup.h [URL]

If someone can do this, I believe it will make a nice addition to the Basket application for all.

Also I am not running Kubuntu I am running Karmic 9.10 64 bit

View 8 Replies View Related

CentOS 5 :: Creating A Simple Live CD That Executes A Shell Script?

Mar 9, 2010

I would like to a build a CD image (of CentOS 5, x86_64 that loads into memory and boots to the OS without installing anything to hard drives. Then I would like the system to execute a shell script automatically. The shell script will have commands that will control execution.

The goal of this exercise is basically to pre-configure a system (RAID config, BIOS update, etc) automatically using the shell script before installing the OS. I would like the ability to change the shell script as needed and probably repackage the ISO image. I would prefer not to deal with building a source tree to accomplish this. this is something one could do using mkisofs.

View 1 Replies View Related

Red Hat / Fedora :: Creating Web Page For Users With Restricted Shell To Change System Pw?

Feb 3, 2011

I have a box that's used as an SFTP server. All users have restricted shell so they can only use SFTP to send and receive files. But it makes it hard to have them change their passwords. I thought that if we had a web page set up where the user could enter their username, old password, new password and confirmed new password, that this would be the easiest solution.

View 1 Replies View Related

Programming :: Prevent "leak" Into Shell From A Customized Shell Menu Script?

Dec 15, 2009

I've created a simple script based menu. This menu will be accessed by only a certain users via ssh.When user logs in, the menu will automatically run. (configured at user's .bash_profile).How do I force the session to close when user hits Ctrl-C or Ctrl-Break ?In a nutshell, I don't want user to have access to shell.

View 11 Replies View Related

Programming :: Array Containing Words In C?

Sep 24, 2010

This array is supposed to contain 12 elements (names of the month) What I want to achieve is that depending on some user input (a number 1-12) a full name of one of the months will be displayed, eg.

Code:
scanf("%d", &month);
printf("The month is %c", months_names[month]);

View 6 Replies View Related







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