Read from script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read from script
# 1  
Old 05-06-2009
Read from script

Hi all.

I'm a newbie of bash scripting.

I need to create a script to have a rotate backup with 5 USB DISK on a work week.
With e2label, I've labelled all disk with all day of the week ( e.g. Monday, Tuesday, Thursday,... ).

How can I read if I've plugged the right device ?!?!

I find the right day with "date +%A".

Thanks a lot.

filloweb.
# 2  
Old 05-06-2009
This is my script:

Code:
#!/bin/sh
#Device check

RIGHT_BACKUP_SUPPORT=`date +%A`
USB_DISK_DEVICE=`/sbin/blkid | grep "${RIGHT_BACKUP_SUPPORT}" |cut -d: -f1`
USB_DISK_LABEL=`/sbin/e2label "${USB_DISK_DEVICE}"`

if
    [ "${USB_DISK_LABEL}" = "${RIGHT_BACKUP_SUPPORT}" ];
then
    echo "The right disk is in !!!!";
else
    echo "Change it!!!"
fi

When the wrong disk is attached, I've some error:

Code:
[root@linviterie Desktop]# ./device_check.sh 
/sbin/e2label: No such file or directory while trying to open 
Couldn't find valid filesystem superblock.
Change it!!!
[root@linviterie Desktop]#

I need to implement a mail whit a request to change the wrong ( with label in mail ) to the right disk.

Thanks.
filloweb.
# 3  
Old 05-06-2009
Code:
USB_DISK_LABEL=`/sbin/e2label "${USB_DISK_DEVICE}" 2>/tmp/disk.txt`
if [ $? -ne 0 ]; then
mailx -s "Replace disk" abc@dot.com < /tmp/disk.txt
exit 1
fi

cheers,
Devaraj Takhellambam
# 4  
Old 05-06-2009
Hi,

I can't understand...

Is right this?!?!

Code:
#!/bin/sh
#Device check
RIGHT_BACKUP_SUPPORT=`date +%A`
USB_DISK_DEVICE=`/sbin/blkid | grep "${RIGHT_BACKUP_SUPPORT}" |cut -d: -f1`
USB_DISK_LABEL=`/sbin/e2label "${USB_DISK_DEVICE}" 2>/tmp/disk.txt`
if [ $? -ne 0 ]; then
mailx -s "Replace disk" f.a@b.c < /tmp/disk.txt
exit 1
fi

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Read space in script

Hi All, Please let me know how to read space between 2 words in script. It is reading only first chars ES,NZ. But after space it is not reading next 3 chars. ES LPI NZ GBL FR LPI DK LPI for v_sob_cntry_cd in `cat /shared/set_of_books_cntry_cd_list.lst` do ... (6 Replies)
Discussion started by: kiranparsha
6 Replies

2. Shell Programming and Scripting

Script read variable with for

Hi All, How I can read on variable with cycle for in bash script e.g.#!/bin/bash VAR1=`command1 sentence list` for i in $(cat $VAR1); do VAR2=`command2 $i` echo $VAR2 doneSo read VAR1 execute command over this and load in VAR2 then print VAR2, Thanks you, Please wrap... (1 Reply)
Discussion started by: aav1307
1 Replies

3. Shell Programming and Scripting

Script to read a log file and run 2nd script if the dates match

# cat /tmp/checkdate.log SQL*Plus: Release 11.2.0.1.0 Production on Mon Sep 17 22:49:00 2012 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production FIRST_TIME NEXT_TIME... (1 Reply)
Discussion started by: SarwalR
1 Replies

4. UNIX for Dummies Questions & Answers

Read Bash Script

I am very new to all these programming languages and really love Linux but have only begun to dive into bash scripting... I am curious what's going on with this script... #!/bin/bash if ; then # xen grep control_d /proc/xen/capabilities >& /dev/null if ; then # domU -- do not run on... (2 Replies)
Discussion started by: BrianBlaze
2 Replies

5. Shell Programming and Scripting

Script read highest value

Hi All, Can someone help steer me to the simplest approach to write a script that reads the second column of a csv file and returns the highest value. example file: DATE,QUANTITY Mon Apr 30 01:56:00 2012,42 Mon Apr 30 02:24:00 2012,72 Mon Apr 30 02:56:00 2012,102 Mon Apr 30 02:59:00... (3 Replies)
Discussion started by: dekker74
3 Replies

6. Shell Programming and Scripting

[SCRIPT] read and substitution

Hi all, Actually I have a huge bash file like: port1=$PORT && if ; then ..... ....stuff port2=$PORT && if ; then ..... ...stuff port3=$PORT && if ; then ..... ...stuff port4=$PORT && if ; then ..... ...stuff port5=$PORT && if ; then ..... I would like to change the $port inside... (2 Replies)
Discussion started by: Dedalus
2 Replies

7. Shell Programming and Scripting

Script to read a file

Can someone please give me a big help? I'm trying to read the file below, which have the format: query,XX,XX,6559,0.132,0.210,0.108,0.03% query,XX,XX,6559,0.132,0.210,0.108,0.03% query,XX,XX,6559,0.132,0.210,0.108,0.03% Need to get the 4th value: 6559 and sum all and put it into a var: ... (2 Replies)
Discussion started by: letakeda
2 Replies

8. UNIX for Advanced & Expert Users

Script without read permission but execute the script

I have a script, except me no one can read the script but they can execute the script. Is it possible? (14 Replies)
Discussion started by: kingganesh04
14 Replies

9. UNIX for Dummies Questions & Answers

help with simple read script!

Hi y'all...I've been wracking my brain over this very simple script that reads in a textfile and echos each line. But I keep getting an error. Below is my script: #!/bin/bash while read myline do echo $myline done < t_file-20080221.01.asc The error I am getting is: syntax error... (1 Reply)
Discussion started by: kevlar28
1 Replies

10. Shell Programming and Scripting

how other user cannot read my script?

Hi All, If I don't want other user read my script, what can i do? :confused: (19 Replies)
Discussion started by: happyv
19 Replies
Login or Register to Ask a Question