/usr/bin/find && -exec /bin/rm never work as expected

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat /usr/bin/find && -exec /bin/rm never work as expected
# 1  
Old 09-30-2010
/usr/bin/find && -exec /bin/rm never work as expected

hi there,

Would you able to advise that why the syntax or statement below couldn't work as expected ?

Code:
/usr/bin/find /backup -name "*tar*" -mtime +2 -exec /bin/rm -f {} \; 1> /dev/null 2>&1

In fact, I was initially located it as in crontab job, but it doesn't work at all. So, I was thinking to rather put it into a shell script and executed as crontab script. Anyway, both do not work at all. The system environment is bash shell.

I am purely execute it as in terminal, it works pretty fine. Here are the bash_profile and bashrc for reference.

Code:
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME
# Set autologout after 30 min inactivity for root
if [ "`id -u`" = "0" ]; then
TMOUT=1800
trap clear 0
fi

Code:
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
[root@tas-tem-1 ~]# cat /etc/bashrc
# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# by default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ "`id -gn`" = "`id -un`" -a `id -u` -gt 99 ]; then
        umask 002
else
        umask 022
fi

# are we an interactive shell?
if [ "$PS1" ]; then
    case $TERM in
        xterm*)
                if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
                else
                PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
                fi
                ;;
        screen)
                if [ -e /etc/sysconfig/bash-prompt-screen ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
                else
                PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\033\\"'
                fi
                ;;
        *)
                [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
            ;;
    esac
    # Turn on checkwinsize
    shopt -s checkwinsize
    [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
fi

if ! shopt -q login_shell ; then # We're not a login shell
        for i in /etc/profile.d/*.sh; do
            if [ -r "$i" ]; then
                . $i
            fi
        done
        unset i
fi


Please kindly enlighten. Thanks

Last edited by pludi; 09-30-2010 at 10:13 AM..
# 2  
Old 09-30-2010
Quote:
Originally Posted by rauphelhunter
Would you able to advise that why the syntax or statement below couldn't work as expected ?
A good way to figure it out would be not to drop its standard and error outputs in the first place.
# 3  
Old 10-01-2010
hi

In fact, even without the standard output, it won't work as well before I put up to the forum.


Quote:
/usr/bin/find /backup -name "*tar*" -mtime +2 -exec /bin/rm -f {} \;
Thx.. Hope to hear more suggestion
# 4  
Old 10-01-2010
No error messages ?
# 5  
Old 10-02-2010
try it without the exec. See if anything returns.
# 6  
Old 10-04-2010
Hi,

No error at all. If without exec, it won't work at all.

It doesn't work only when been scheduled in crontab.
# 7  
Old 10-04-2010
Please provide facts, i.e. a reproducible case and more details about what you expect the command to do but do not observe. "It won't work" or "It doesn't work" isn't sufficient to understand your issue.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

>& >&! in /bin/csh

i am new player in linux what does mean ">& and >&!" in script or command line? thanks (4 Replies)
Discussion started by: abdossamad2003
4 Replies

2. UNIX for Dummies Questions & Answers

/usr/bin/ld: cannot find -lboost_regex-mt

...... (30 Replies)
Discussion started by: larry burns
30 Replies

3. Solaris

What is the difference between xpg4/bin and usr/bin?

Hi Experts, I found that the same commands(sort, du, df, find, grep etc.) exists in both dir. What is the difference to use them? i.e: to use xpg4/bin/grep and usr/bin/grep My OS version is SunOS 5.10 Regards, Saps (7 Replies)
Discussion started by: saps19
7 Replies

4. OS X (Apple)

When to use /Users/m/bin instead of /usr/local/bin (& whats the diff?)?

Q1. I understand that /usr/local/bin means I can install/uninstall stuff in here and have any chance of messing up my original system files or effecting any other users. I created this directory myself. But what about the directory I didn't create, namely /Users/m/bin? How is that directory... (1 Reply)
Discussion started by: michellepace
1 Replies

5. Solaris

Questions about /usr/local/bin & scripts.

Hi gentlemen. For what intended is the directory /usr/local/bin? In this directory are some script. I don't understand how these scripts being in this directory are started. Each time after registration of the user occurs start of these scripts. These scripts start applications. (7 Replies)
Discussion started by: wolfgang
7 Replies

6. UNIX for Dummies Questions & Answers

Alias /usr/bin to /bin in profile

Hi! All the basic linux commands, ie. echo, find, etc, are located in /bin. I have a couple of programs that have these commands pointed towards /usr/bin, ie, /usr/bin/echo (even though the actual 'echo' command is in /bin). How can I alias or redirect or link the /usr/bin to /bin just for this... (6 Replies)
Discussion started by: dancerat
6 Replies

7. Shell Programming and Scripting

#/usr/bin/csh -f not working as expected?

Hey everyone, A coworker of mine has written a csh script that starts with #!/usr/bin/csh -f. It's my understanding that the -f should skip the .cshrc and .login files, but here's the problem: In the script "line" is used, and I happen to have a "line" in my ~/bin. When the script is ran my... (4 Replies)
Discussion started by: effigy
4 Replies

8. UNIX for Dummies Questions & Answers

Difference between /bin, /usr/bin, /sbin ?

Hi All, Can somebody tell me the difference between /bin, /usr/bin, /sbin ? Thanx in advance, Saneesh Joseph (3 Replies)
Discussion started by: saneeshjose
3 Replies

9. UNIX for Dummies Questions & Answers

/bin/sh: /usr/bin/vi: No such file or directory when doing crontab

I just set up an ftp server with Red Hat 5.2. I am doing the work, I'm baby stepping, but it seems like every step I get stuck. Currently, I'm trying to set up a crontab job, but I'm getting the following message: /bin/sh: /usr/bin/vi: No such file or directory. I see that vi exists in /bin/vi,... (3 Replies)
Discussion started by: kwalter
3 Replies
Login or Register to Ask a Question