LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-03-2019, 03:01 PM   #1
finalturismo
Member
 
Registered: May 2019
Posts: 120

Rep: Reputation: Disabled
[Request] Subtract all numbers from specific column, [drive wiper Project]


I need to subtract all numbers (0-9) from a specific column

any help would be greatly appreciated.

Best Regards,

Last edited by finalturismo; 10-03-2019 at 06:29 PM.
 
Old 10-03-2019, 03:13 PM   #2
OstermanA
Member
 
Registered: Dec 2006
Location: Seattle, WA
Distribution: CentOS 8
Posts: 99

Rep: Reputation: 20
Can you give an example of the type of data you have as input, and precisely what you want to have output? The answer is probably sed, but I would need to see more to see how to set it up.
 
Old 10-03-2019, 03:18 PM   #3
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Yes. Please show us the data you're working with and you've tried.
See the How To Ask a Question link in my signature.

Last edited by scasey; 10-03-2019 at 03:19 PM.
 
Old 10-03-2019, 03:28 PM   #4
finalturismo
Member
 
Registered: May 2019
Posts: 120

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
Yes. Please show us the data you're working with and you've tried.
See the How To Ask a Question link in my signature.
watch ls "/dev/sd*"

outputs the following

/dev/sda
/dev/sda1
/dev/sda2
/dev/sda3
/dev/sda4
/dev/sdb
/dev/sdc
/dev/sdd
/dev/sde


I need the partitions with the numbers subtracted so that when i am inserting drives i can see the drives pop up without the partitions.
I pretty much don't want to see the partitions of the drives and just the drives. so far i have revived a lot of help from these forums with a project i am working on and i am almost done. I will create a posting with pictures of what i am doing when i am done so everyone can see what they contributed to. I just need help with a few udev rules after this so i can prevent hardware freezes with shorted drives.
 
Old 10-03-2019, 03:33 PM   #5
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
You can use sed to delete the lines containing numbers.

ls /dev/sd* | sed '/[0-9]/d'

Last edited by dugan; 10-03-2019 at 03:39 PM.
 
Old 10-03-2019, 03:44 PM   #6
finalturismo
Member
 
Registered: May 2019
Posts: 120

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dugan View Post
You can use sed to delete the lines containing numbers.

ls /dev/sd* | sed '/[0-9]/d'
Thanks that was exactly what i needed!!!
 
Old 10-03-2019, 03:47 PM   #7
finalturismo
Member
 
Registered: May 2019
Posts: 120

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dugan View Post
You can use sed to delete the lines containing numbers.

watch ls /dev/sd* | sed '/[0-9]/d'
Thanks that was exactly what i needed!!!

Now i need udev to run this command when any usb or drive is inserted to a drive bay. watch ls /dev/sd* | sed '/[0-9]/d' | nl

Anyone know the udev rule to set for this?

So for some reason the watch command messes up the output.

Last edited by finalturismo; 10-03-2019 at 04:00 PM.
 
Old 10-03-2019, 03:53 PM   #8
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Code:
ls /dev/sd?
should show you only those entries with one character following the 'sd' Just another way...
 
1 members found this post helpful.
Old 10-03-2019, 05:11 PM   #9
finalturismo
Member
 
Registered: May 2019
Posts: 120

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
Code:
ls /dev/sd?
should show you only those entries with one character following the 'sd' Just another way...
That would work fine the problem is, iam processing up to 74 drives at a time.

I am working on a drive wiper project i need a udev rule added to /etc/udev/rules.d/ to run a specific command when a drive gets detected as inserted, into the bay. (sata ports and usb ports)

I want the hard drive shreder to show health status and start wiping right when drives are inserted. So far i have the health status log complete and shreding part done, thanks to you guys.

I just need the command to start a script with udev now

once i am done i am going to take pictures and show you guys what you helped me with, might even be able to turn this into a wiping distro for server cabinets

any help on the udev rules would be FABULOUS.
 
Old 10-03-2019, 05:28 PM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
watch runs continuously and uses cursor commands to display the desired information at the same position which is probably why it messes with sed and no output. As far as I know udev would be a background process and not associated with a terminal window so your not going do see anything anyway.

I think you can use a dialog or window notification box to display the desired information. Please explain exactly what you are trying to accomplish with the display output.

Last edited by michaelk; 10-03-2019 at 05:30 PM.
 
Old 10-03-2019, 05:58 PM   #11
finalturismo
Member
 
Registered: May 2019
Posts: 120

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
watch runs continuously and uses cursor commands to display the desired information at the same position which is probably why it messes with sed and no output. As far as I know udev would be a background process and not associated with a terminal window so your not going do see anything anyway.

I think you can use a dialog or window notification box to display the desired information. Please explain exactly what you are trying to accomplish with the display output.
ok well that makes sense, not much really i need it to display the following in the terminal window

i want to create a udev rule like follows but iam not sure if i have it right

so for example


This is the code i tried so far, for udev. it runs the script when i restart udev service but not when i insert drive.


udev when drive 1 inserted
Code:
ACTION=="add" ,KERNEL=="sdb", RUN+="/bin/smartdrive1"
udev when drive 2 inserted
Code:
ACTION=="add" ,KERNEL=="sdc", RUN+="/bin/smartdrive2"
the shred all command will be running the following command for each drive

udev action to do drive 1
Code:
hdsentinel -solid -dev /dev/sdb | ts %Y/%m/%d-%H:%M:%S |& tee -a smartlog.1 && shred /dev/sdb -v
udev action to do drive 2
Code:
hdsentinel -solid -dev /dev/sdc | ts %Y/%m/%d-%H:%M:%S |& tee -a smartlog.1 && shred /dev/sdc -v

So far the code to execute works but the udev rule does not fully work, it does execute in background when i restart service though. This is my first time trying to do a udev script. Man if i get this right, it going to be so cool XD. Yall have been helping a lot so far.s

I need udev to also run this command so i can see the drives i am inserting in the terminal.
/dev/sd* | sed '/[0-9]/d' | nl

Last edited by finalturismo; 10-03-2019 at 06:03 PM.
 
Old 10-03-2019, 07:59 PM   #12
finalturismo
Member
 
Registered: May 2019
Posts: 120

Original Poster
Rep: Reputation: Disabled
ZOMG i got it to work
the correct udev rule was
Code:
KERNEL=="sdb", ACTION=="add", RUN+="/bin/testhds"
Now all i need to do, is get it to redirect terminal output to the correct terminal session. I have no earthly clue where to start on that one.
 
Old 10-03-2019, 08:35 PM   #13
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
I don't think you can. I was thinking something like udevadm to monitor udev events might work.

https://wiki.archlinux.org/index.php/Udisks
 
Old 10-06-2019, 01:15 PM   #14
finalturismo
Member
 
Registered: May 2019
Posts: 120

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
I don't think you can. I was thinking something like udevadm to monitor udev events might work.

https://wiki.archlinux.org/index.php/Udisks
I was able to find a solution using the following at the end of the command.

Code:
 shred -v /dev/sdb >> /dev/pts/0 2>&1
the send to command does not show verbose for shred at the pts/0 terminal. As soon as you add 2>&1 it is able to forward verbose to terminal correctly.

I found this when looking at similar request on google , took my a while to find.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to subtract selective values in multi row multi column (awk or sed ?) nricardo Linux - Newbie 2 10-20-2012 09:55 AM
[SOLVED] Sum numbers in a column in a specific block Alkass Programming 3 07-15-2011 01:12 PM
How can i subtract two non-real (aka decimal'd) numbers via bash onesikgypo Programming 3 04-28-2010 11:55 AM
subtract total numbers of files from 2 directories Michael235 Linux - Newbie 2 03-28-2009 05:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration