Sponsored Content
Full Discussion: creating array variable
Top Forums Shell Programming and Scripting creating array variable Post 302124052 by scriptingmani on Thursday 28th of June 2007 10:09:01 AM
Old 06-28-2007
creating array variable

Hi all,

i am quite fimiliar with shell scripting but i wouldn't regard myself as a semi professional at it.

I am trying to create an array variable to read in 4 lines from a file using head and tail command in a pipeline and store each line into each array. I have done the scripting in unix but for some reason i keep getting syntax errors during runtime saying 'mon=' unexpected.

for the moment i am trying to create a simple script to store months Jan, Feb Mar Apr into array mon but its not having it and i don't know why. i did google searches and i tried a number of the examples i found but none work
i tried to use declare -a mon but it says "declare: not found" - is it something to do with the first line - #!/bin/bash?
#!/bin/bash

mon=( Jan Feb Mar Apr )

echo $mon

can someone please throw some light onto this becuase its doing my head in.

thanks in advance

Mani
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

creating a dynamic array in ksh

Hi, Is it possible to create a dynamic array in shell script. I am trying to get the list of logfiles that created that day and put it in a dynamic array. I am not sure about it. help me New to scripting Gundu (3 Replies)
Discussion started by: gundu
3 Replies

2. Shell Programming and Scripting

creating a dynamic array

i want to create an array the array elements are populated depending upon the number of entries present in a data file The data file is created dynamically how to achieve the same thanks (1 Reply)
Discussion started by: trichyselva
1 Replies

3. Programming

Creating an array to hold posix thread ids: Only dynamic array works

I am facing a strange error while creating posix threads: Given below are two snippets of code, the first one works whereas the second one gives a garbage value in the output. Snippet 1 This works: -------------- int *threadids; threadids = (int *) malloc (num_threads * sizeof(int)); ... (4 Replies)
Discussion started by: kmehta
4 Replies

4. Shell Programming and Scripting

creating variable array name

#!/bin/ksh #export CLASSPATH=$CLASSPATH:~dialp/cso/classes:/opt/oracle/product/8.1.6/jdbc/lib/classes12.zip #export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/oracle/product/8.1.6/lib DATE="`date '+%m%d%Y'`" PATH=.:$PATH export PATH town_name='123' town_name='123' town_name='345'... (1 Reply)
Discussion started by: priyanka3006
1 Replies

5. Shell Programming and Scripting

Creating array containing file names

I am wondering how I can save the file names (stored in $file or $fnames) in array which I can access with an index. alias MATH 'set \!:1 = `echo "\!:3-$" | bc -l`' set narg = $#argv while ($iarg < $narg) MATH iarg = $iarg + 1 set arg = $argv set opt = ` echo $arg | awk... (1 Reply)
Discussion started by: kristinu
1 Replies

6. Shell Programming and Scripting

Problem with array and creating directories

I have an interesting requirement. I have declaried an array like :- arr=`find . ! -name "." | xargs -I {} echo {} | cut -c 2-${#}` Then i will try to access the array elements like :- i=0 for i in ${arr}; do Here comes the confusions, the array elements are basically dir and files stored... (2 Replies)
Discussion started by: Renjesh
2 Replies

7. Shell Programming and Scripting

Creating bash array name from variable

Hi gurus, I need to create arrays from variables, via a loop. The issue I have is with the array name creation. How do I use a variable to define an array? I want to do something like declare -a $H where $H is my loop variable. I then need to add items to each array I've created,... (3 Replies)
Discussion started by: melias
3 Replies

8. UNIX for Dummies Questions & Answers

Creating an array

I am having trouble creating an array, I've tried everything google gives me but it won't work, and it seems as though it should. Using Ubunto 12.04 and bash. #!/bin/bash ARRAY=one two three echo ${ARRAY}When I do this I receive the error : two: not found and : Bad substitution When I... (3 Replies)
Discussion started by: jrymer
3 Replies

9. Shell Programming and Scripting

Creating array from file

Dear community, how can I create an array from file taking only the 4th field? out.txt file is something like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20So the final array should be: 4 8 12 16 20With this command I created an array with all the fields, but I need only the 4th... (13 Replies)
Discussion started by: Lord Spectre
13 Replies

10. Shell Programming and Scripting

Creating an array with options as an argument!

Hi Guys, I am writting a c shell script where I have to parse an input argument with options that could be an array. So far I have achieved where I could parse a single argument with option but failed when I try to create an array with the options. For example: This is on terminal window:... (2 Replies)
Discussion started by: dixits
2 Replies
Mon::Client(3pm)					User Contributed Perl Documentation					  Mon::Client(3pm)

NAME
Mon::Client - Methods for interaction with Mon client SYNOPSIS
use Mon::Client; DESCRIPTION
Mon::Client is used to interact with "mon" clients. It supports a protocol-independent API for retrieving the status of the mon server, and performing certain operations, such as disableing hosts and service checks. METHODS
new Creates a new object. A hash can be supplied which sets the default values. An example which contains all of the variables that you can initialize: $c = new Mon::Client ( host => "monhost", port => 2583, username => "foo", password => "bar", ); password (pw) If pw is provided, sets the password. Otherwise, returns the currently set password. host (host) If host is provided, sets the mon host. Otherwise, returns the currently set mon host. port (portnum) If portnum is provided, sets the mon port number. Otherwise, returns the currently set port number. username (user) If user is provided, sets the user login. Otherwise, returns the currently set user login. prot If protocol is provided, sets the protocol, specified by a string which is of the form "1.2.3", where "1" is the major revision, "2" is the minor revision, and "3" is the sub-minor revision. If protocol is not provided, the currently set protocol is returned. protid ([protocol]) Returns true if client and server protocol match, false otherwise. Implicitly called by connect. If protocol is specified as an integer, supplies that protocol version to the server for verification. version Returns the protocol version of the remote server. error Returns the error string from set by the last method, or undef if there was no error. connected Returns 0 (not connected) or 1 (connected). connect (%args) Connects to the server. If host and port have not been set, uses the defaults. Returns undef on error. If $args{"skip_protid"} is true, skip protocol identification upon connect. disconnect Disconnects from the server. Return undef on error. login ( %hash ) %hash is optional, but if specified, should contain two keys, username and password. Performs the "login" command to authenticate the user to the server. Uses username and password if specified, otherwise uses the username and password previously set by those methods, respectively. checkauth ( command ) Checks to see if the specified command, as executed by the current user, is authorized by the server, without actually executing the command. Returns 1 (command is authorized) or 0 (command is not authorized). disable_watch ( watch ) Disables watch. disable_service ( watch, service ) Disables a service, as specified by watch and service. disable_host ( host ) Disables host. enable_watch ( watch ) Enables watch. enable_service ( watch, service ) Enables a service as specified by watch and service. enable_host ( host ) Enables host. set ( group, service, var, val ) Sets var in group,service to val. Returns undef on error. get ( group, service, var ) Gets variable var in group,service and returns it, or undef on error. quit Logs out of the server. This method should be followed by a call to the disconnect method. list_descriptions Returns a hash of service descriptions, indexed by watch and service. For example: %desc = $mon->list_descriptions; print "$desc{'watchname'}->{'servicename'} "; list_deps Lists dependency expressions and their components for all services. If there is no dependency for a particular service, then the value will be "NONE". %deps = $mon->list_deps; foreach $watch (keys %deps) { foreach $service (keys %{$deps{$watch}}) { my $sref = \%{$deps{$watch}->{$service}}; print "expr ($watch,$service) = $sref->{expression} "; print "components ($watch,$service) = @{$sref->{components}} "; } } list_group ( hostgroup ) Lists members of hostgroup. Returns an array of each member. list_watch Returns an array of all the defined watch groups and services. foreach $w ($mon->list_watch) { print "group=$w->[0] service=$w->[1] "; } list_opstatus ( [group1, service1], ... ) Returns a hash of per-service operational statuses, as indexed by watch and service. The list of anonymous arrays is optional, and if is not provided then the status of all groups and services will be queried. %s = $mon->list_opstatus; foreach $watch (keys %s) { foreach $service (keys %{$s{$watch}}) { foreach $var (keys %{$s{$watch}{$service}}) { print "$watch $service $var=$s{$watch}{$service}{$var} "; } } } list_failures Returns a hash in the same manner as list_opstatus, but only the services which are in a failure state. list_successes Returns a hash in the same manner as list_opstatus, but only the services which are in a success state. list_disabled Returns a hash of disabled watches, services, and hosts. %d = $mon->list_disabled; foreach $group (keys %{$d{"hosts"}}) { foreach $host (keys %{$d{"hosts"}{$group}}) { print "host $group/$host disabled "; } } foreach $watch (keys %{$d{"services"}}) { foreach $service (keys %{$d{"services"}{$watch}}) { print "service $watch/$service disabled "; } } for (keys %{$d{"watches"}}) { print "watch $_ disabled "; } list_alerthist Returns an array of hash references containing the alert history. @a = $mon->list_alerthist; for (@a) { print join (" ", $_->{"type"}, $_->{"watch"}, $_->{"service"}, $_->{"time"}, $_->{"alert"}, $_->{"args"}, $_->{"summary"}, " ", ); } list_dtlog Returns an array of hash references containing the downtime log. @a = $mon->list_dtlog for (@a) { print join (" ", $_->{"timeup"}, $_->{"group"}, $_->{"service"}, $_->{"failtime"}, $_->{"downtime"}, $_->{"interval"}, $_->{"summary"}, " ", ); } list_failurehist Returns an array of hash references containing the failure history. @f = $mon->list_failurehist; for (@f) { print join (" ", $_->{"watch"}, $_->{"service"}, $_->{"time"}, $_->{"summary"}, " ", ); } list_pids Returns an array of hash references containing the list of process IDs of currently active monitors run by the server. @p = $mon->list_pids; $server = shift @p; for (@p) { print join (" ", $_->{"watch"}, $_->{"service"}, $_->{"pid"}, " ", ); } list_state Lists the state of the scheduler. Returns a two-element array. The first element of the array is 0 if the scheduler is stopped, and 1 if the scheduler is currently running. The second element of the array returned is the string "scheduler running" if the scheduler is currently running, and if the scheduler is stopped, the second element is the time(2) that the scheduler was stopped. @s = $mon->list_state; if ($s[0] == 0) { print "scheduler stopped since " . localtime ($s[1]) . " "; } start Starts the scheduler. stop Stops the scheduler. reset Resets the server. reload ( what ) Causes the server to reload its configuration. what is an optional argument, and currently the only supported option is auth, which reloads the authorization file. term Terminates the server. set_maxkeep Sets the maximum number of history entries to store in memory. get_maxkeep Returns the maximum number of history entries to store in memory. test ( test, group, service [, exitval, period]) Schedules a service test to run immediately, or tests an alert for a given period. test must be monitor, alert, startupalert, or upalert. To test alerts, the exitval and period must be supplied. Periods are identified by their label in the mon config file. If there are no period tags, then the actual period string must be used, exactly as it is listed in the config file. test_config Tests the syntax of the configuration file. Returns a two-element array. The first element of the array is 0 if the syntax of the config file is invalid, and 1 if the syntax of the config file is OK. The second element of the array returned is the failure message, if the config file has invalid syntax, and the result code if the config file syntax is OK. This function returns undef if it cannot get a connection or a response from the mon server. Config file checking stops as soon as an error is found, so you will need to run this command more than once if you have multiple errors in your config file in order to find them all. @s = $mon->test_config; if ($s[0] == 0) { print "error in config file: " . $s[1] . " "; } ack ( group, service, text ) When group/service is in a failure state, acknowledges this with text, and disables all further alerts during this failure period. loadstate ( state ) Loads state. savestate ( state ) Saves state. servertime Returns the time on the server using the same output as the time(2) system call. send_trap ( %vars ) Sends a trap to a remote mon server. Here is an example: $mon->send_trap ( group => "remote-group", service => "remote-service", retval => 1, opstatus => "fail", summary => "hosta hostb hostc", detail => "hosta hostb and hostc are unresponsive", ); retval must be a nonnegative integer. opstatus must be one of fail, ok, coldstart, warmstart, linkdown, unknown, timeout, untested. Returns undef on error. perl v5.14.2 2012-04-27 Mon::Client(3pm)
All times are GMT -4. The time now is 01:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy