Delayed execution on shell script

0

I made a simple script file on my linux machine to mount a iscsi drive.

iscsiadm –m node --targetname THE_TARGET_IQN --login
mount /dev/sdb1 /home/mounted

The problem is, When I exceuted this script, It always fail at first time. Likes this.

/etc/init.d# ./iscsi
Loggin to [iface: default, target: targetname, portal: THE_TARGET_IQN (multiple)
Loggin to [iface: default, target: targetname, portal: THE_TARGET_IQN successful.
mount: special device /dev/sdb1 does not exist
/etc/init.d# ./iscsi
isciadm: default:1 session requested, but 1 already present.
isciadm: Could not log into all portals
/etc/init.d#

I think that If I can insert some delay between two lines, It will be fine. Is this reasonable?. Please advise me for this.

Andrei Kim

Posted 2017-12-13T19:51:45.367

Reputation: 51

What's the relationship between the first & second lines? – Xen2050 – 2017-12-13T22:22:31.840

The first one is engaging a ISCSI And second one is to mount a ISCSI volume – Andrei Kim – 2017-12-14T05:19:25.367

I don't have iscsiadm on my system, but a web man page doesn't appear to have any options to make it wait before returning to the terminal... little weird that it returns immediately before it's finished, but it looks like sleep is your best option, +1 to Deeh – Xen2050 – 2017-12-14T18:05:42.887

Answers

1

If all you need is delay between two commands, you can add sleep X, where X is value in seconds.

iscsiadm –m node --targetname THE_TARGET_IQN --login
sleep 3
mount /dev/sdb1 /home/mounted

If you need it to mount on boot (it's not clear from your post). Then you need to add /dev/sdb1 to /etc/fstab with _netdev option and make sure iSCSI is running on boot.

Deeh

Posted 2017-12-13T19:51:45.367

Reputation: 204

Hi. I wanted to mount on boot as you mentioned. Thanks. So I made a script file to the /etc/init as an startup script. If there is better way, Can you share with me? – Andrei Kim – 2017-12-14T05:29:06.750

Have a look at this https://askubuntu.com/questions/499246/iscsi-auto-startup-at-boot-14-04

– Deeh – 2017-12-15T18:08:59.780