Sponsored Content
Full Discussion: Menu driven using Ksh
Top Forums UNIX for Advanced & Expert Users Menu driven using Ksh Post 8561 by g-e-n-o on Sunday 14th of October 2001 07:06:18 PM
Old 10-14-2001
something like this script below, it is written for MKS toolkit to be run on windows but it's based on ksh, it's pretty simple, used for uncompress zips and rars, menu based, simple menu though



Code:
#!/bin/ksh

# dir ---------> nombre de directorio
# numzip ------> cantidad de zips que hay en cada directorio
# zipname -----> nombre de cada zip en el directorio
# numrar ------> cantidad de rars que hay en cada directorio
# rarname -----> nombre de cada rar en el directorio
# log  --------> ruta de los logs
# data --------> directorio de software
# identstr ----> las 3 primeras letras de los ficheros, sirve como wild card

export log=e:\/download\/\/log
export data=e:\/download\/\/rips
export ddate=`date +%C%y%m%d`

unzip()
{
for dir in `grep ^ dir.txt`
do	
	cd $dir
	echo "checking for zips in $dir" >> $log\/${ddate}error.txt
	ls *.zip > zip.txt 2>> $log\/${ddate}error.txt
	if [ $? -eq 0 ]
	then
	numzip=`cat zip.txt | wc -l`
	identstr=`head -1 zip.txt | awk '{print substr($1, 1,3)}'`
	pkunzip -od $identstr\*.zip >> $log\/${ddate}uncompress.log
	status=$?
		if [ `ls *.zip | wc -l` -gt $numzip ]
		then
			echo "More zips were extracted in $dir" >> $log\/${ddate}error.txt
		fi
		case $status in
		0) for zipname in `grep ^ zip.txt`
		   do	
			rm $zipname
		   done
		   ;;
		1) echo "Pkunzip exits with error status 1"
		   ;;
		11) echo "CRC Error during zip extraction in $dir, Status 11" >> $log\/${ddate}error.txt
		    ;;
		*) print "Unexpected exit status, error in $dir" >> $log\/${ddate}error.txt
		   ;;
		esac
	fi
	cd $data
done
}

unrar()
{
for dir in `grep ^ dir.txt`
do	
	cd $dir
	echo "checking for rars in $dir" >> $log\/${ddate}error.txt
	ls *.r* > rar.txt 2>> $log\/${ddate}error.txt
	if [ $? -eq 0 ]
	then
	numrar=`cat rar.txt | wc -l`
	identstr=`head -1 rar.txt | awk '{print substr($1, 1,3)}'`
	rar x -z -y $identstr\*.rar >> $log\/${ddate}uncompress.log
	status=$?
		if [ `ls *.r* | wc -l` -gt $numrar ]
		then
			echo "More rars were extracted in $dir" >> $log\/${ddate}error.txt
		fi
		case $status in
		0) for rarname in `grep ^ rar.txt`
		   do	
			rm $rarname
		   done
		   ;;
		3) echo "CRC Error during rar extraction in $dir" >> $log\/${ddate}error.txt
		   ;;
		*) print "Unexpected exit status, error in $dir" >> $log\/${ddate}error.txt
		   ;;
		esac
	fi
	cd $data
done
}

cleanup()
for dir in `grep ^ dir.txt`
do	
	cd $dir
	rm rar.txt zip.txt *.diz 2>> $log\/${ddate}error.txt
	cd $data
done

echo "Please select uncompressing options"
echo "1. unzip only"
echo "2. unrar only"
echo "3. unzip & unrar"
echo "4. unzip, unrar & cleanup"
echo "5. cleanup only\n"

read option

echo "Error Log starting.........................................\n" > $log\/${ddate}error.txt
echo "Process Log starting.........................................\n" > $log\/${ddate}uncompress.log

case $option in
1) unzip
   ;;
2) unrar
   ;;
3) unzip
   unrar
   ;;
4) unzip
   unrar
   cleanup
   ;;
5) cleanup
   ;;
*) print "Please insert options 1 ~ 5"
   ;;
esac

 

10 More Discussions You Might Find Interesting

1. Programming

menu driven ( like pine) on Linux

Hi guys, I am designing the rdbms in C/C++ on linux platform as my project. Can any one help me in designing menu driven screen (like the pine ) which will print on screen as follows 1) create table 2) add table ............. etc with arrow keys for... (2 Replies)
Discussion started by: amit
2 Replies

2. UNIX for Advanced & Expert Users

Menu Driven UNIX Admin

I need to have a script that can do an automated IPL function (how to reboot the box). I think ‘reboot’ would do the trick. However, how would I go about doing it, for example if the user states from a menu script that I would like to reboot now. The problem is when I do the ‘reboot’ command I... (6 Replies)
Discussion started by: ad4m88
6 Replies

3. Homework & Coursework Questions

Menu Driven Shell Script which accepts1 to 5 options

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1) Write a Menu Driven Shell Script which accepts1 to 5 options and performs the following actions for... (1 Reply)
Discussion started by: vaghya
1 Replies

4. Shell Programming and Scripting

Menu driven Script needed ..pls help

Hi Guys.. am new to unix scrpiting..I need a Menu need to create using shell scrpting eg: Food items ready paid if i press "f" need to add items for a file food items.. if i press "r" it need to move into ready and remove from food items if i press "p" need to update a filed in... (1 Reply)
Discussion started by: sasdua
1 Replies

5. UNIX for Dummies Questions & Answers

What is a menu or command line option driven script?

i'm confused what this means. i was asked to design a menu or command line option driven script that reads out of a DB and displays info such as read_data.pl -u <user> -e <event> which would print commands run by <user>with the <event> in the db. any suggestions? i've been using... (2 Replies)
Discussion started by: kpddong
2 Replies

6. Shell Programming and Scripting

Help needed in writing a menu driven script

Hi, I was wondering if someone could help me write a shell script in Linux that backsup/restores data to anywhere I choose but it needs to be menu driven? Thanks, I'm new to Linux/Unix but liking it so far...just hoping to get to grips with the scripts! :) (7 Replies)
Discussion started by: Nicole
7 Replies

7. Shell Programming and Scripting

Menu driven script.

I'm a beginner at scripting and have been putting this script together over the past week. It's no where as polish as it could be. Any tips/suggestions on improving this script would be appreciate it. Every week, my team develops WAR files in tomcat on our test environment and moves them to our... (4 Replies)
Discussion started by: bouncer
4 Replies

8. Shell Programming and Scripting

Use of stty vs trap in script-driven login menu

My employers would like me to selectively run one of several different (already-existing) Korn Shell menu-driven scripts out of the user's .profile file, depending on some yet-to-be-specified user critieria. I've never done this kind of thing, but I have the existing scripts (among other... (5 Replies)
Discussion started by: Clovis_Sangrail
5 Replies

9. UNIX for Dummies Questions & Answers

System administration tasks performed from a menu driven interface

I need to write a shell script that allows some system-administration tasks to be preformed automatically from a menu-driven interface. Automate the following tasks: • Copy directory tree • Delete files or directories • Output Information But I don't understand the question. What is a "menu... (2 Replies)
Discussion started by: femchi
2 Replies

10. Shell Programming and Scripting

Using menu driven script

Hi Team , I wrote a shell script for adding and subtracting two numbers am getting error could some one please help to fix it script: echo "Enter 1 to add:" echo "Enter 2 to sub:" echo "Enter 3 for both addition and subtraction :" read ans; case "$ans" in 1)... (4 Replies)
Discussion started by: knz
4 Replies
Widgets::Menu(3pm)					User Contributed Perl Documentation					Widgets::Menu(3pm)

NAME
Curses::Widgets::Menu - Menu Widgets MODULE VERSION
$Id: Menu.pm,v 1.103 2002/11/14 01:26:34 corliss Exp corliss $ SYNOPSIS
use Curses::Widgets::Menu; $menu = Curses::Widgets::Menu->new({ COLUMNS => 10, INPUTFUNC => &scankey, FOREGROUND => undef, BACKGROUND => 'black', FOCUSSWITCH => " ", X => 1, Y => 1, MENUS => { MENUORDER => [qw(File)], File => { ITEMORDER => [qw(Save Quit)], Save => &Save, Quit => &Quit, }, CURSORPOS => 'File', BORDER => 1, }); $menu->draw($mwh, 1); $menu->execute; See the Curses::Widgets pod for other methods. REQUIREMENTS
Curses Curses::Widgets Curses::Widgets::ListBox DESCRIPTION
Curses::Widgets::Menu provides simplified OO access to menus. Each item in a menu can be tied to a subroutine reference which is called when selected. METHODS
new (inherited from Curses::Widgets) $menu = Curses::Widgets::Menu->new({ INPUTFUNC => &scankey, FOREGROUND => undef, BACKGROUND => 'black', FOCUSSWITCH => " ", MENUS => { MENUORDER => [qw(File)], File => { ITEMORDER => [qw(Save Quit)], Save => &Save, Quit => &Quit, }, CURSORPOS => 'File', BORDER => 1, }); The new method instantiates a new Menu object. The only mandatory key/value pairs in the configuration hash are X and Y. All others have the following defaults: Key Default Description ============================================================ INPUTFUNC &scankey Function to use to scan for keystrokes FOREGROUND undef Default foreground colour BACKGROUND 'black' Default background colour FOCUSSWITCH " " Characters which signify end of input MENUS {} Menu structure CURSORPOS '' Current position of the cursor BORDER 0 Avoid window borders The MENUS option is a hash of hashes, with each hash a separate menu, and the constituent hashes being a Entry/Function pairs. Each hash requires a special key/value pair that determines the order of the items when displayed. Each item is separated by two spaces. draw $menu->draw($mwh, 1); The draw method renders the menu in its current state. This requires a valid handle to a curses window in which it will render itself. The optional second argument, if true, will cause the selection cursor to be rendered as well. popup $menu->popup; This method causes the menu to be displayed. Since, theoretically, the menu should never be seen unless it's being actively used, we will always assume that we need to draw a cursor on the list as well. execute $menu->execute; This method acts like the standard Curses::Widgets method of the same name, with the exception being that selection of any menu item will also cause it to exit (having already called the associated item subroutine). HISTORY
2002/10/17 -- First implementation AUTHOR
/COPYRIGHT (c) 2001 Arthur Corliss (corliss@digitalmages.com) perl v5.8.8 2006-09-14 Widgets::Menu(3pm)
All times are GMT -4. The time now is 05:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy