LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux Mint
User Name
Password
Linux Mint This forum is for the discussion of Linux Mint.

Notices


Reply
  Search this Thread
Old 05-11-2018, 05:03 AM   #1
Buttery
LQ Newbie
 
Registered: May 2018
Posts: 5

Rep: Reputation: Disabled
Custom Shell Script "missing operand"?


I was wanting to create a simple "double click" solution for shredding areas of mine or my families drives. I'm not too familiar with shell scripts at all but the one I'm trying to use is pretty simple but I can't exactly figure out what I need to do to get it do work!

The .sh file looks something like this:
#!/bin/sh
sudo for i in <drive> ; do shred -fvzn0 $i & done

whenever I try to run it, it asks for the password then immediately closes the window. if I attempt to run the .sh from terminal then it says something along the lines of "Shred: missing shred operand".

Any ideas..?
 
Old 05-11-2018, 05:04 AM   #2
Buttery
LQ Newbie
 
Registered: May 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
Not sure if it makes any difference, but I also attempting this same thing using Ubuntu and get the same issue
 
Old 05-11-2018, 05:19 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,308
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
You might add the following as the second line so that you can preview each line to see what really runs:

Code:
set -x
Then you might add the following after done to catch all the background processes.

Code:
wait
 
Old 05-11-2018, 05:24 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
In addition to the above where is <drive> defined?
 
Old 05-11-2018, 05:28 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,308
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Also, the sudo is in the wrong place.

So instead of this:

Code:
sudo for i in <drive> ; 
do 
        shred -fvzn0 $i & 
done
Try this:

Code:
for i in <drive> ; 
do 
        sudo shred -fvzn0 $i & 
done
Otherwise $i will be empty because the for was run as a different user and thus in a different environment.

That will also make it easier to lock down in /etc/sudoers
 
Old 05-11-2018, 05:29 AM   #6
Buttery
LQ Newbie
 
Registered: May 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
You might add the following as the second line so that you can preview each line to see what really runs:

Code:
set -x
Then you might add the following after done to catch all the background processes.

Code:
wait
After using these suggestions it looks like the one line command is just reading "sudo for i in <drive>" and nothing passed the semi-colon.

Normally I'd do
Code:
sudo su
for i in /dev/sdb ; do shred -fvzn0 $i & done
 
Old 05-11-2018, 05:32 AM   #7
Buttery
LQ Newbie
 
Registered: May 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
Also, the sudo is in the wrong place.

So instead of this:

Code:
sudo for i in <drive> ; 
do 
        shred -fvzn0 $i & 
done
Try this:

Code:
for i in <drive> ; 
do 
        sudo shred -fvzn0 $i & 
done
Otherwise $i will be empty because the for was run as a different user and thus in a different environment.

That will also make it easier to lock down in /etc/sudoers
With this Terminal didn't even open
 
Old 05-11-2018, 05:34 AM   #8
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,308
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
The terminal should not open. That is correct.

Wind back a bit and please explain how you intend to launch this script, where you are getting your drive values from, and what you have in /etc/sudoers to lock all this down?
 
Old 05-11-2018, 05:39 AM   #9
Buttery
LQ Newbie
 
Registered: May 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
I had just wanted it to be something that I can launch by double click > run in terminal

Drive volumes from disks

and no changes to /etc/sudoers
 
Old 05-11-2018, 06:02 AM   #10
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,308
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Ok. There are at least two steps in this. First, get it working as you like it in the terminal. Then get it working via an icon using a .desktop file.

As far as step one goes, for the For Loop, are you typing in the list of drives or partitions by hand? Or are you getting them as output from a program or script?
 
Old 05-12-2018, 07:08 PM   #11
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
If it's of any use to you, I use a recursive shred script written in bash (which I name shredd and call as a Caja action):

Code:
#!/bin/bash

function shredProcess {
  if [ -d "$1" ] ; then
    rmdir "$1"
    if [ $? -ne 0 ]; then
      echo "*** ERROR - $1 could not be deleted"
    fi
  elif [ -f "$1" ] ; then
    shred -n 1 "$1" # overwrite with random data
    sync # force sync of buffers to disk
    shred -n 0 -z -u "$1" # overwrite with zeroes and remove file
    if [ $? -ne 0 ]; then
      echo "*** ERROR - $1 could not be deleted"
    fi
  fi
}
                
for f in "$@" # handle spaces in filenames
do
  if [ -d "$f" ] ; then
    find "$f" -depth -print0 | while IFS= read -r -d '' file
    do 
      shredProcess "$file"
    done
  elif [ -f "$f" ] ; then
    shredProcess "$f"
  fi
done
 
Old 05-13-2018, 12:58 AM   #12
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by Buttery View Post
for i in <drive> ;
this is wrong - the string '<drive>' is a pseudocode placeholder for something you need to fill in. it is NOT shell syntax.
also i'm not sure if shred works on drives or partitions. did you read its documentation?
i suspect you need "for i in <partitions>" instead.

edit: if you use the term "drive" in a windows mentality, you actually mean partitions.
 
  


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] Shell Script: "bash: Bad Substitution - Script for remove "." " thiagofw Programming 14 12-09-2016 10:04 PM
"mkdir: missing operand" error when installing Linux gnuub Linux - Newbie 1 05-17-2011 02:28 PM
[SOLVED] Errors executing shell script: "command not found" and "no such file or directory" eko000 Linux - Newbie 1 01-14-2011 07:54 AM
Error message "dirname: missing operand" when starting acroread thethinker Slackware 2 08-19-2010 09:49 AM
Shell script: I have string "abc____def____ghi", how to make "abc def ghi" vouser Programming 8 03-09-2010 10:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux Mint

All times are GMT -5. The time now is 01:15 AM.

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