# Read from script

**URL:** <https://community.unix.com/t/read-from-script/239453>\
**Category:** Shell Programming and Scripting\
**Created:** [May 6, 2009, 11:20am UTC](https://community.unix.com/t/read-from-script/239453 "2009-05-06T11:20:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![filloweb](https://community.unix.com/letter_avatar/filloweb/32/6_449c533f586939b6e5f246632a46421f.png) [@filloweb](https://community.unix.com/u/filloweb)\
**Post date:** [May 6, 2009, 11:20am UTC](https://community.unix.com/t/read-from-script/239453/1 "2009-05-06T11:20:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![filloweb](https://community.unix.com/letter_avatar/filloweb/32/6_449c533f586939b6e5f246632a46421f.png) [@filloweb](https://community.unix.com/u/filloweb)\
**Post date:** [May 6, 2009, 11:27am UTC](https://community.unix.com/t/read-from-script/239453/2 "2009-05-06T11:27:18Z")

</div>

This is my script:

```nohighlight
#!/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:

```nohighlight
[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.

---

<div class="post-metadata">

**Author:** ![devtakh](https://community.unix.com/letter_avatar/devtakh/32/6_449c533f586939b6e5f246632a46421f.png) [@devtakh](https://community.unix.com/u/devtakh)\
**Post date:** [May 6, 2009, 12:17pm UTC](https://community.unix.com/t/read-from-script/239453/3 "2009-05-06T12:17:31Z")

</div>

```nohighlight
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

---

<div class="post-metadata">

**Author:** ![filloweb](https://community.unix.com/letter_avatar/filloweb/32/6_449c533f586939b6e5f246632a46421f.png) [@filloweb](https://community.unix.com/u/filloweb)\
**Post date:** [May 6, 2009, 12:34pm UTC](https://community.unix.com/t/read-from-script/239453/4 "2009-05-06T12:34:18Z")

</div>

Hi,

I can't understand...

Is right this?!?!

```nohighlight
#!/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.
