Need help on bash scripting in Linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help on bash scripting in Linux
# 1  
Old 04-08-2015
RedHat Need help on bash scripting in Linux

Could anyone help me with the below scripting task.

my requirement is as below

1. I have two directories /var/tmp/dir1 & /var/tmp/dir2
once i run the script test.sh it should ask as below.

Please choose the below path 1 (or) 2
1. /var/tmp/dir1
2. /var/tmp/dir2
else. exit

2. once i enter 1, it should go to the path /var/tmp/dir1/08042015/

here is a directory 08042015 (ddmmyyyy) with current date

3. in 08042015 dir - redirect the output of the command "ls -lrt" to a file if output count (ls -lrt |wc -l > 10). (if output found redirect or wait for ls -lrt the output)
# 2  
Old 04-08-2015
Hi and welcome to the forums.

What have you tried so far?
Please use the code tags (next to php) to show code or terminal output.
Where are you stuck?

Have a nice day.
# 3  
Old 04-08-2015
Sorry Sir. I do not know how to write the scripting.
# 4  
Old 04-08-2015
Try this (untested):
Code:
strDate=$(date +'%d%m%Y')
outputFile=~/myLog.txt

select curDir in  /var/tmp/dir1   /var/tmp/dir2
do	cd "$curDir/$strDate"
	echo "$PWD" >> "$outputFile"
	data=$(ls -lrt)
	num=$(echo "$data" | wc -l)
	[ $num -gt 10 ] && \
		echo >> "$outputFile"
done

gtg & hth

Last edited by Corona688; 04-08-2015 at 12:20 PM..
# 5  
Old 04-08-2015
Is this homework?
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

bash scripting help

Hi Guys i have a <script?> that spits out the location of each printer using snpget here is the code for i in `sed -n '/Start Printer/,/End Printer/p' /hosts/blah/etc/dhcp/hosts.conf | awk '!/^#/ {print $2}' | egrep -v \... (2 Replies)
Discussion started by: ab52
2 Replies

2. Shell Programming and Scripting

Bash scripting

Try to imagine a flag: nnnnx nnnxx nnxxx nxxxx now imagine how it will output: 4 times the "n"and 1 times "x" 3 times "n"and" 2 times" x " .. etc. .. rhombus is the same only instead of "n" is there gap "and " x "is a few times to form the correct shape Can you help... (3 Replies)
Discussion started by: krcek12
3 Replies

3. Shell Programming and Scripting

please help with Bash Scripting????

Hi, can anyone help me with my scrip please. I wanted do following tasks: 1. List all the directory 2. A STDIN to ask user to enter a directory name from listed directories 3. command to check if the directory exists( or a command to validate if the user entered a valid directory name) ... (2 Replies)
Discussion started by: eminjan
2 Replies

4. Shell Programming and Scripting

bash scripting help!!

Hi, can anyone help me with my scrip please. I wanted do following tasks: 1. List all the directory 2. A STDIN to ask user to enter a directory name from listed directories 3. command to check if the directory exists( or a command to validate if the user entered a valid directory name)... (3 Replies)
Discussion started by: eminjan
3 Replies

5. Shell Programming and Scripting

bash scripting help

hi all i'm trying to get a script working upon connection with pppd According to docu this happens ina clean environment with a couple of variables set, namely $1,$2,... To be able to execute the statements i included a path statement but i think i'm running into trouble with the variables -... (6 Replies)
Discussion started by: jimjones
6 Replies

6. UNIX for Dummies Questions & Answers

Should I do a bash scripting course?!

Hello, I'm confused (oh, yes). I'm running Linux at work. When I type 'echo $SHELL' I am told that I'm running tcsh. In /bin I note that both tcsh and bash are listed. Question 1: Can I swap to run bash rather than tcsh and, if so, how will this affect my system? Is there any advantage to... (6 Replies)
Discussion started by: macpete
6 Replies

7. Shell Programming and Scripting

Bash Scripting

Hello there peeps: There is a little piece of bash shell scripting problem i have, which i was hoping you could help me with. #!/bin/bash stored_word() { case $(( $$ % 8 )) in 0 ) echo "energy";; 1 ) echo "touch";; 2 ) echo "climbing";; 3 ) echo... (3 Replies)
Discussion started by: keyvan
3 Replies
Login or Register to Ask a Question