Run this script in the current bash terminal shell window, but have it open shred in another bash terminal shell window?

Mikx4

New Member
Joined
Nov 23, 2018
Messages
15
Reaction score
2
Credits
206
I have this script which I manually execute in one bash terminal shell, after I have executed this in another bash terminal window:
shred -n 0 -vfz /dev/sdXY

All the script does is show me iostat for the current device, and give me a time counter of how long shred is taking. I could do "time" in front of shred but that only tells me the total time taken, not a running counter and doesn't show iostat for the device I am shredding, so I have this script to do what I want.

I would like it all to be encompassed in one script so I only have to execute it with the device name.

Any ideas about incorporating it all in one script greatly appreciated.

#!/bin/bash
z=0
while true; do
a=$(ps -ef | grep -v grep | grep -q shred ; echo $?)
#echo $a
if [ $a == 0 ]; then
# echo "shred is running."
iostat -hy /dev/$1 1 1 | grep -E "Device|$1"
echo $(($z/60))":"$(($z%60))
((z+=1))
else
sleep 1
exit 1
fi
done

Thank you.
 


I'm uncertain as to whether the following is quite what you want, but it may be of interest.

As I understand it, you would like a single script to display a "running counter" of the shred as it is happening on the device you are shredding.

I was unable to get shred to provide the sort of detail of progress that I could get by using the pv and the dd commands to zero out a device. For example, the following command produced the output shown:
Code:
[root@min ~]# pv -ptrbf /dev/zero | dd of=/dev/sda bs=1M status=progress
2095357952 bytes (2.1 GB, 2.0 GiB) copied, 1 s, 2.1 GB/s1.95GiB 0:00:01 [1.94GiB/s]
2261295104 bytes (2.3 GB, 2.1 GiB) copied, 2 s, 1.1 GB/s2.11GiB 0:00:02 [ 158MiB/s]
2499461120 bytes (2.5 GB, 2.3 GiB) copied, 4 s, 624 MB/s2.33GiB 0:00:04 [ 113MiB/s]
2581495808 bytes (2.6 GB, 2.4 GiB) copied, 6 s, 429 MB/s2.40GiB 0:00:06 [25.2MiB/s]
2594078720 bytes (2.6 GB, 2.4 GiB) copied, 7 s, 369 MB/s2.42GiB 0:00:07 [11.9MiB/s]
2602401792 bytes (2.6 GB, 2.4 GiB) copied, 8 s, 324 MB/s2.42GiB 0:00:08 [7.87MiB/s]
2614657024 bytes (2.6 GB, 2.4 GiB) copied, 10 s, 261 MB/s2.44GiB 0:00:10 [5.25MiB/s]
<snip>
3972796416 bytes (4.0 GB, 3.7 GiB) copied, 262 s, 15.2 MB/s3.70GiB 0:04:22 [5.83MiB/s]
3978964992 bytes (4.0 GB, 3.7 GiB) copied, 263 s, 15.1 MB/s3.71GiB 0:04:23 [5.93MiB/s]
3993112576 bytes (4.0 GB, 3.7 GiB) copied, 265 s, 15.1 MB/s3.72GiB 0:04:25 [6.54MiB/s]
3999666176 bytes (4.0 GB, 3.7 GiB) copied, 266 s, 15.0 MB/s3.73GiB 0:04:26 [6.25MiB/s]
4006219776 bytes (4.0 GB, 3.7 GiB) copied, 267 s, 15.0 MB/s3.73GiB 0:04:27 [6.25MiB/s]

dd: error writing '/dev/sda': No space left on device
3.73GiB 0:04:27 [14.3MiB/s]
0+88830 records in
0+88829 records out
4007264256 bytes (4.0 GB, 3.7 GiB) copied, 782.965 s, 5.1 MB/s

The device was a 4G usb (about 3.73GiB).
The output showed the bytes covered for each second of progress at the start of the line, and at the end of the line, the speed of transfer in MiB/s.
At the end of the process, there was a delay before the terminal was returned to a prompt presumably because of dd doing its thing.

The shred program may be more what you desire or need. The zeroing is sufficient here and basically just used to "clean" usbs before reformatting. Sometimes users actually do multiple zeroing for their security needs, like shred can overwrite a number of times but I can't say ultimately at which point they become more or less as effective as each other.
 
Last edited:
I'm uncertain as to whether the following is quite what you want, but it may be of interest.

As I understand it, you would like a single script to display a "running counter" of the shred as it is happening on the device you are shredding.

I was unable to get shred to provide the sort of detail of progress that I could get by using the pv and the dd commands to zero out a device. For example, the following command produced the output shown:
Code:
[root@min ~]# pv -ptrbf /dev/zero | dd of=/dev/sda bs=1M status=progress
2095357952 bytes (2.1 GB, 2.0 GiB) copied, 1 s, 2.1 GB/s1.95GiB 0:00:01 [1.94GiB/s]
2261295104 bytes (2.3 GB, 2.1 GiB) copied, 2 s, 1.1 GB/s2.11GiB 0:00:02 [ 158MiB/s]
2499461120 bytes (2.5 GB, 2.3 GiB) copied, 4 s, 624 MB/s2.33GiB 0:00:04 [ 113MiB/s]
2581495808 bytes (2.6 GB, 2.4 GiB) copied, 6 s, 429 MB/s2.40GiB 0:00:06 [25.2MiB/s]
2594078720 bytes (2.6 GB, 2.4 GiB) copied, 7 s, 369 MB/s2.42GiB 0:00:07 [11.9MiB/s]
2602401792 bytes (2.6 GB, 2.4 GiB) copied, 8 s, 324 MB/s2.42GiB 0:00:08 [7.87MiB/s]
2614657024 bytes (2.6 GB, 2.4 GiB) copied, 10 s, 261 MB/s2.44GiB 0:00:10 [5.25MiB/s]
<snip>
3972796416 bytes (4.0 GB, 3.7 GiB) copied, 262 s, 15.2 MB/s3.70GiB 0:04:22 [5.83MiB/s]
3978964992 bytes (4.0 GB, 3.7 GiB) copied, 263 s, 15.1 MB/s3.71GiB 0:04:23 [5.93MiB/s]
3993112576 bytes (4.0 GB, 3.7 GiB) copied, 265 s, 15.1 MB/s3.72GiB 0:04:25 [6.54MiB/s]
3999666176 bytes (4.0 GB, 3.7 GiB) copied, 266 s, 15.0 MB/s3.73GiB 0:04:26 [6.25MiB/s]
4006219776 bytes (4.0 GB, 3.7 GiB) copied, 267 s, 15.0 MB/s3.73GiB 0:04:27 [6.25MiB/s]

dd: error writing '/dev/sda': No space left on device
3.73GiB 0:04:27 [14.3MiB/s]
0+88830 records in
0+88829 records out
4007264256 bytes (4.0 GB, 3.7 GiB) copied, 782.965 s, 5.1 MB/s

The device was a 4G usb (about 3.73GiB).
The output showed the bytes covered for each second of progress at the start of the line, and at the end of the line, the speed of transfer in MiB/s.
At the end of the process, there was a delay before the terminal was returned to a prompt presumably because of dd doing its thing.

The shred program may be more what you desire or need. The zeroing is sufficient here and basically just used to "clean" usbs before reformatting. Sometimes users actually do multiple zeroing for their security needs, like shred can overwrite a number of times but I can't say ultimately at which point they become more or less as effective as each other.
Thanks for that. I have incorporated and replaced my own script.

Zeroing USB sticks is something other people say to do to repair and make the USB drive operate better. I have no idea whether that is true or not.
 
[root@min ~]# pv -ptrbf /dev/zero | dd of=/dev/sda bs=1M status=progress
You made me go and look up the pv command. Thanks for that! I had never heard of it before.
 
After reading the man page on shred I was intrigued.

Is your script strictly for overwriting a device or for the exact timing of the practice of the changing of the permissions, overwriting or de-allocating process?
OR> doing both as mentioned above and monitoring the progress at the same time?

Always interested in learning new things as I write for the Linux Community. :)
Alex
 


Follow Linux.org

Members online

No members online now.

Top