Script runs but does not execute rm -rf command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script runs but does not execute rm -rf command
# 1  
Old 02-25-2013
Script runs but does not execute rm -rf command

Hi!

First off I'm no bin/bash script writer! Smilie I can make heads and tales of it from the php experience I have and that's all.

Now I managed to piece this script together to go look at directory and remove files that are +60 days. It's finding the files but its not removing them. I believe I have the command right.

Here's my script albeit short ..

Code:
#!/bin/bash
IFS=”$”
cpanel_username=*********
domain=ftsoccerclub.org 
username=mflores
cd /home/${cpanel_username}/mail/${domain}/${username}
find -P /home/${cpanel_username}/mail/${domain}/${username}/* -mindepth 1 -maxdepth 1 -mtime +60 | while read old; do
echo “Deleting ${old}…”
rm -rf “${old}”
done

and then I'll get an email from the server telling me ...

Code:
“Deleting /home/ftsoccer/mail/ftsoccerclub.org/mflores/cur/1352080174.H191427P31791.aegis.provim.net,S=5532:2,…”
“Deleting /home/ftsoccer/mail/ftsoccerclub.org/mflores/cur/1352906954.H115090P16065.aegis.provim.net,S=17638:2,…”
“Deleting /home/ftsoccer/mail/ftsoccerclub.org/mflores/cur/1353454848.H164807P5507.aegis.provim.net,S=5482:2,…”
“Deleting /home/ftsoccer/mail/ftsoccerclub.org/mflores/cur/1352658395.H166861P17720.aegis.provim.net,S=23414:2,…”
“Deleting /home/ftsoccer/mail/ftsoccerclub.org/mflores/cur/1353519624.H550535P18176.aegis.provim.net,S=5236:2,…”
“Deleting /home/ftsoccer/mail/ftsoccerclub.org/mflores/cur/1352724748.H508350P20254.aegis.provim.net,S=23200:2,…”
“Deleting /home/ftsoccer/mail/ftsoccerclub.org/mflores/cur/1351785142.H117822P22505.aegis.provim.net,S=11548:2,…”
“Deleting /home/ftsoccer/mail/ftsoccerclub.org/mflores/cur/1352287307.H69509P3896.aegis.provim.net,S=26245:2,…”
“Deleting /home/ftsoccer/mail/ftsoccerclub.org/mflores/cur/1353537904.H596136P16093.aegis.provim.net,S=77013:2,…”
“Deleting /home/ftsoccer/mail/ftsoccerclub.org/mflores/cur/1352129497.H679409P15661.aegis.provim.net,S=15964:2,…”

and if I go back to that directory .. the file still stands! |=

The permission on the file(s) is 660

The cpanel username I use is like God on here so I don't think it's a permission issue .. then again I could be wrong!

Any help would be greatly appreciated!

Last edited by Scrutinizer; 02-25-2013 at 12:29 PM.. Reason: quote tags => code tags
# 2  
Old 02-25-2013
Editing your script in Microsoft Word has filled it with nasty Smart Quotes, not regular " quotes. Fix those and try your script again.
# 3  
Old 02-25-2013
Thanks! I didn't even see that! I use Notepad++ not sure what happened there. Guess this is one for the mental rolodex! =)

Could you give me a hint what I can do if I have multiple users to do this to?

Works like a charm now! =)
# 4  
Old 02-25-2013
Multiple users running your script? Or what?
# 5  
Old 02-25-2013
Sorry should have elaborated ..

The username in this script was

username=mflores

Although I have 20 or so more users to go through the directories to clear our mail older then 60+ days.

I'm the only person running the script, through cron job of course.

Thanks!
# 6  
Old 02-25-2013
Suggestions to make you script more robust.
Code:
cd ... || exit # fatal

Code:
... while read -r old ...

And never never edit such a script with a Microsoft editor!
# 7  
Old 02-28-2013
Hmmmmm.

Code:
while IFS=" " read cpanel_username domain username
do
        echo "cpanel_username=${cpanel_username}"
        echo "domain=${domain}"
        echo "username=${username}"

        # Sanity checking, skip bad names
        [ -d "/home/${cpanel_username}/mail/${domain}/${username}" ] || continue
        ...
done < /path/to/listofnames

...where listofnames has one entry per line separated by spaces.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

2. Shell Programming and Scripting

Sql command inside shell script runs without giving anything back as outout

#!/bin/sh # This script returns the number of rows updated from a function echo "The execution is starting ....." sqlplus -silent $UP <<EOF set serveroutput on set echo off set pagesize 0 VAR no_rows_updated NUMBER; EXEC :no_rows_updated :=0; DECLARE CURSOR c_update is SELECT * FROM... (4 Replies)
Discussion started by: LoneRanger
4 Replies

3. Shell Programming and Scripting

Script runs in command-line fine but times out in CRON?

Hi, I have a script that seems to run to completion when in the command-line, but when it is run using the cron, it seems to time out. They both start and run fine, but on the CRON it stops prematurely. The script hits an API every few seconds and grabs data. Does anyone have any idea on... (4 Replies)
Discussion started by: phpchick
4 Replies

4. Shell Programming and Scripting

When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found" My code is as follows: -------------------------- #!/bin/sh user="test" DIR="/bldtmp/"$user VIEW="test.view1" echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies

5. UNIX for Dummies Questions & Answers

How to execute command after telneting in shell script?

Hi , I have to write a shell script to telnet to specific host and execute the admin command there. Please help me to do that. Eg : telnet hostname portno admin command exit (3 Replies)
Discussion started by: arukuku
3 Replies

6. Shell Programming and Scripting

CRON shell script only runs correctly on command line

Hi, I'm new to these forums, and I'm hoping that someone can solve this problem... To make things short: I have DD-wrt set up on a router. I'm trying to run a script in CRON that fetches the daily password from my database using SSH. CRON is set like so(in web interface): * * * *... (4 Replies)
Discussion started by: louieaw
4 Replies

7. Shell Programming and Scripting

Shell script runs fine in Solaris, in Linux hangs at wait command

HI, I have a strange problem. A shell script that runs fine on solaris. when i ported to linux, it started hanging. here is the core of the script CFG_FILE=tab25.cfg sort -t "!" -k 2 ${CFG_FILE} | egrep -v "^#|^$" | while IFS="!" read a b c do #echo "jobs output" #jobs #echo "jobs... (13 Replies)
Discussion started by: aksaravanan
13 Replies

8. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

9. Shell Programming and Scripting

how to execute a sh command from a csh script

Hi everyone, I have a csh script that works fine but the output of an rsh command is different if I use boune shell instead cshell. Is there the possibility to execute only this command in bourne shell from a script declared cshell? Thanks Christian (2 Replies)
Discussion started by: bonovox
2 Replies

10. Shell Programming and Scripting

shell script to execute user command

I don't know why the following shell script doesn't work. Could you please help me out? #!/usr/bin/ksh test="cal > /tmp/tmp.txt 2>&1" $test I know it will work for the following format: #!/usr/bin/ksh cal > /tmp/tmp.txt 2>&1 However, I need to get the command from the user in... (1 Reply)
Discussion started by: redtiger
1 Replies
Login or Register to Ask a Question