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
dos2unix(1)						      General Commands Manual						       dos2unix(1)

NAME
dos2unix - DOS/MAC to UNIX text file format converter SYNOPSYS
dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...] Options: [-hkqV] [--help] [--keepdate] [--quiet] [--version] DESCRIPTION
This manual page documents dos2unix, the program that converts plain text files in DOS/MAC format to UNIX format. OPTIONS
The following options are available: -h --help Print online help. -k --keepdate Keep the date stamp of output file same as input file. -q --quiet Quiet mode. Suppress all warning and messages. -V --version Prints version information. -c --convmode convmode Sets conversion mode. Simulates dos2unix under SunOS. -o --oldfile file ... Old file mode. Convert the file and write output to it. The program default to run in this mode. Wildcard names may be used. -n --newfile infile outfile ... New file mode. Convert the infile and write output to outfile. File names must be given in pairs and wildcard names should NOT be used or you WILL lost your files. EXAMPLES
Get input from stdin and write output to stdout. dos2unix Convert and replace a.txt. Convert and replace b.txt. dos2unix a.txt b.txt dos2unix -o a.txt b.txt Convert and replace a.txt in ASCII conversion mode. Convert and replace b.txt in ISO conversion mode. Convert c.txt from Mac to Unix ascii format. dos2unix a.txt -c iso b.txt dos2unix -c ascii a.txt -c iso b.txt dos2unix -c mac a.txt b.txt Convert and replace a.txt while keeping original date stamp. dos2unix -k a.txt dos2unix -k -o a.txt Convert a.txt and write to e.txt. dos2unix -n a.txt e.txt Convert a.txt and write to e.txt, keep date stamp of e.txt same as a.txt. dos2unix -k -n a.txt e.txt Convert and replace a.txt. Convert b.txt and write to e.txt. dos2unix a.txt -n b.txt e.txt dos2unix -o a.txt -n b.txt e.txt Convert c.txt and write to e.txt. Convert and replace a.txt. Convert and replace b.txt. Convert d.txt and write to f.txt. dos2unix -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt DIAGNOSTICS
BUGS
The program does not work properly under MSDOS in stdio processing mode. If you know why is that so, please tell me. AUTHORS
Benjamin Lin - <blin@socs.uts.edu.au> Bernd Johannes Wuebben (mac2unix mode) <wuebben@kde.org> MISCELLANY
Tested environment: Linux 1.2.0 with GNU C 2.5.8 SunOS 4.1.3 with GNU C 2.6.3 MS-DOS 6.20 with Borland C++ 4.02 Suggestions and bug reports are welcome. SEE ALSO
unix2dos(1) mac2unix(1) 1995.03.31 dos2unix v3.0 dos2unix(1)
All times are GMT -4. The time now is 02:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy