ctrl-c in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ctrl-c in shell script
# 1  
Old 07-04-2012
ctrl-c in shell script

The below script has Perl script in it where it gives the usage details.

filer.sh

Code:
echo
echo -en "Enter filer : "
read filer
echo "test.pl -f $filer -F L"


Output
=========


Code:
The following hosts are online and available:
Name            Total     Allocated          Used     Available     Allocated %       Used %
-----------------------------------------------------------------------------------------------
pool1        25984 GB      25486 GB      14745 GB      11238 GB         98 %         57 %
Enter the name of the pool you want to use:


In the above output I need to press ctrl-c to come our of perl script.

Could anyone help me modifying the script so that the script should come out shell script without pressing the ctrl-c
# 2  
Old 07-04-2012
Include the exit scenario in test.pl perl script .. Post the code of it ..
# 3  
Old 07-04-2012
Here is the code for perl script.

The perl script is inbuilt script which I am using to list pools

(LP) List Pools

Below is the code of perl


Code:
Enter the action you would like to perform: ';
                chomp ($opt{F} = <STDIN>);
#               $opt{F} = uc($opt{F});
        } until ($opt{F} =~ m/^A$|^M$|^R$|^D$|^L$|^LP$|^Lp$|^Ls$|^LS$|^CS$|^DS$|^RS$|^C$|^B$/);
        return;
}

# Validate a pool supplied on the cmd line
sub _validate_pool {
        my ($args) = shift;
        # $args->{pools}         => the pool data from the filer.
        # $args->{pool_to_check} => The pool to verify.

        # Go through the pool data and if the pool_to_check matches the data pulled from the filer.
        foreach my $pool_data (@{ $args->{pools} }) {
#               if ($pool_data =~ m/^$args->{pool_to_check}\s+/ && $pool_data =~ m/\s+online\s+/) {
                if ($pool_data =~ m/^$args->{pool_to_check}\s+/) {
                        return 1;

                }
        }
        print "\nWARNING:  Invalid pool specified\n\n";
        return 0;
}

# If the user doesn't specify the pool
sub _get_pool {
        my $ref = shift;
        my @pools = @{ $ref };
        my $input;

        do {
                print "\nThe following pools are online and available:\n";
                printf("%-10s %10s    %10s    %10s    %10s    %10s %% %10s %%\n", "Name", "Total", "Allocated", "Used", "Available", "Alloca                 ted", "Used");
                print("-"x95);
                print "\n";
                foreach my $pool (@pools) {
                        my (@data) = split(/\s+/, $pool);
#                       if ($data[5] eq "online") {
                                printf("%-10s %10d GB %10d GB %10d GB %10d GB %10d %% %10d %%\n", $data[0], $data[1] / 1048576, $data[2] / 1                 048576, $data[3] / 1048576, $data[4] / 1048576, $data[5], $data[6]);
#                       }
                }
                print "\nEnter the name of the pool you want to use: ";
                chomp ($input = <STDIN>);
        }  until ( &_validate_pool({pools => $ref, pool_to_check => $input}));
        return $input;
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automation of keyboard inputs..like Ctrl+d and Ctrl+a

Hi..! I'm stuck with my automation of starting a process and keeping it running even after the current ssh session has exited.. So i'm trying to use command 'screen'. which is doing exactly what i wanted, But the problem is automation of the same. i will have to press Ctrl+a and Ctrl+d for... (2 Replies)
Discussion started by: chandana hs
2 Replies

2. UNIX for Dummies Questions & Answers

Ctrl-V + Ctrl-J for newline character does not work inside vi editor

Hi friends, I am trying to add a newline char ('\n') between the query and the commit statement in the following shell script. #! /bin/sh echo "select * from tab; commit;" > data.sql I have tried typing in "Ctrl-V + Ctrl-J" combination which has inserted ^@ (NUL) character but the commit... (1 Reply)
Discussion started by: royalibrahim
1 Replies

3. Shell Programming and Scripting

How to handle CTRL+Z or CTRL+C in shells script?

Hi, while executing shell script, in the middle of the process, if we kill the shell script( ctrl+z or ctrl+c), script will be killed and the files which using for the script will be in the folder. How to handle those scenarios. Is there any possibilities, if user breaks the script, I need to... (3 Replies)
Discussion started by: ckchelladurai
3 Replies

4. Shell Programming and Scripting

Write a shell script to find ctrl M and delete them

Hi All, I would like to write a shell script to find Control M charactes and after getting the result i want to delete it. But in the script the following command couldn't work. find . -exec grep -l '^M' {} \; > test.txt ^M is ctrl V and M thanks in advance for any help. (4 Replies)
Discussion started by: jatanig
4 Replies

5. Shell Programming and Scripting

Ctrl-C or Ctrl-Z causing exit the session

H! I have written script where it need to invoke the perl script in background, then write the pid in temp file then bring back the job to foreground. whenever the Ctrl-C or Ctrl-Z is pressed in the script has to exit and prompt should be dispalyed. but this script causing exit from shell session... (2 Replies)
Discussion started by: jramesh1
2 Replies

6. UNIX for Dummies Questions & Answers

alias in bash shell for CTRL + l

Is it possible to create an alias wherein it will use a keystroke. Like to clear the screen in bash i have to use CTRL + l. I want to make an alias 'c' out of this. Thanks. (6 Replies)
Discussion started by: or_knob
6 Replies

7. UNIX for Advanced & Expert Users

trap ctrl c in shell script

how to trap the ctrl c in unix shell script my script is running in while loop it should not be terminate with ctrl c. if i press ctrl c while running script it shloud ignore the same. please healp.......... thanks in advance (2 Replies)
Discussion started by: arvindng
2 Replies

8. UNIX for Dummies Questions & Answers

scripting Ctrl-D in a shell

Hi, I want to use the "at" command in a loop to start different processes every hour or so, but I don't know how to script a Ctrl-D so I can escape from the "at" after the last command I want to run and then go to the next command in the loop. Example: i=1 while do j=$((i*60)) at... (2 Replies)
Discussion started by: etownbetty
2 Replies

9. Shell Programming and Scripting

Disabling ctrl-Z key inside shell script

Hi I have tried to disable the CTRL-Z key inside a shell(sh) script using the command trap "`echo "Ctrl-Z key disabled"`" 20But I am not able to exit from the script after pressing CTRL-Z key. How to proceed this? Need reply soon (11 Replies)
Discussion started by: suganthic
11 Replies

10. AIX

Disable ctrl-c,ctrl-d,ctrl-d in ksh script

I wrote a ksh script for Helpdesk. I need to know how to disable ctrl-c,ctrl-z,ctrl-d..... so that helpdesk would not be able to get to system prompt :confused: (6 Replies)
Discussion started by: wtofu
6 Replies
Login or Register to Ask a Question