LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-05-2009, 03:05 AM   #1
vexx
LQ Newbie
 
Registered: Oct 2009
Posts: 3

Rep: Reputation: 0
Bash file...weird problem


I've created a sh file to delete a cache folder for one of my sites. Basically, the bash looks like this:

Code:
#!/bin/bash
rm -fdr cached*
mkdir cached
chmod 0777 cached
When I launch it within the console (root), it does not delete the cached folder and when I "ls -l", I always find another folder called "cached\r".

The cached folder has 0777 permissions all the time, owner root, group root.

The funny part is, I have another site, on the same server, different account and this bash works perfectly.

If I run the commands individually from the console, works perfectly...

I'm puzzled ...

Tnx in advance
 
Old 10-05-2009, 03:09 AM   #2
wfh
Member
 
Registered: Sep 2009
Location: Northern California
Distribution: Ubuntu Debian CentOS RHEL Suse
Posts: 164

Rep: Reputation: 44
Try using full pathnames for your cached folder, such as:

/home/me/cached

...cause when you execute the shell, it does not use your pwd.
 
Old 10-05-2009, 03:13 AM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
If you try to echo the arguments, what do you think would it have expanded to?
Code:
echo rm -fdr cached*
 
Old 10-05-2009, 03:23 AM   #4
vexx
LQ Newbie
 
Registered: Oct 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by konsolebox View Post
If you try to echo the arguments, what do you think would it have expanded to?
Code:
echo rm -fdr cached*
if I echo all the commands, it prints them to the screen, same order as in the sh file.

As for the full path, it's the same thing, tried it now, same result. The sh file is in the root folder, where the dir cached resides.

I've double checked permissions now, all seems ok, I don't rly get it, especially when the same command runs without problems under other account.
 
Old 10-05-2009, 03:25 AM   #5
wfh
Member
 
Registered: Sep 2009
Location: Northern California
Distribution: Ubuntu Debian CentOS RHEL Suse
Posts: 164

Rep: Reputation: 44
Add a "pwd" to your script and pipe the output to a file.

pwd > foo.txt


...see where you're operating at the time you rm the directory.
 
Old 10-05-2009, 03:30 AM   #6
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
How 'bout if you remove the '-f' option. It might print the errors.
 
Old 10-05-2009, 03:43 AM   #7
wfh
Member
 
Registered: Sep 2009
Location: Northern California
Distribution: Ubuntu Debian CentOS RHEL Suse
Posts: 164

Rep: Reputation: 44
"The funny part is, I have another site, on the same server, different account and this bash works perfectly."

What do you mean by "another site"? Another path? Another account? You say it works with the other account, but what is fundamentally different in your account and the other?
 
Old 10-05-2009, 03:44 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Try adding a comment after cached
Code:
mkdir cached # this is a comment
 
Old 10-05-2009, 03:47 AM   #9
wfh
Member
 
Registered: Sep 2009
Location: Northern California
Distribution: Ubuntu Debian CentOS RHEL Suse
Posts: 164

Rep: Reputation: 44
Make your 'rm' command do the following:

rm -rdf cached* 2>&1

...to see if errors are being thrown.
 
Old 10-05-2009, 03:51 AM   #10
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
I don't know how, but I bet you have a DOS line ending on that line and possibly others.

Does 'cat -A file' show

Code:
mkdir cached^M$
(actually, any decent editor should show it if it's there)
 
Old 10-05-2009, 05:24 AM   #11
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by wfh View Post
Make your 'rm' command do the following:

rm -rdf cached* 2>&1

...to see if errors are being thrown.
Why do you think any errors will not be shown already? Stderr is directed to terminal by default so the suggested technique is only necessary if it has been redirected somewhere else earlier.
 
Old 10-05-2009, 05:25 AM   #12
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by slakmagik View Post
I don't know how, but I bet you have a DOS line ending on that line and possibly others.

Does 'cat -A file' show

Code:
mkdir cached^M$
(actually, any decent editor should show it if it's there)
That was my guess, hence suggesting adding the comment so any DOS line end is no longer part of the executed command.
 
Old 10-05-2009, 06:18 AM   #13
vexx
LQ Newbie
 
Registered: Oct 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by catkin View Post
That was my guess, hence suggesting adding the comment so any DOS line end is no longer part of the executed command.
guess what..u're both right...i feel like an idiot..i've edited that file with windows notepad..a while ago and i forgot...left some spaces after the command...ruined it

tnx alot guys for the help
 
Old 10-05-2009, 06:22 AM   #14
SharpyWarpy
Member
 
Registered: Feb 2003
Location: Florida
Distribution: Fedora 18
Posts: 862

Rep: Reputation: 91
Don't know for sure if the "-f" switch negates this, but is your "rm" command aliased to "rm -i"? Try running "rm" like this:
/rm
to see.
 
Old 10-05-2009, 11:17 PM   #15
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I think you mean

\rm
 
  


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
tracks doesn't appear on the file managers - weird problem marciobarbalho Linux - General 4 02-02-2008 06:42 AM
Weird Nautilus Bash Script Problem fatsheep Programming 2 11-19-2006 04:51 PM
Weird File Problem sashhoney Linux - Software 1 05-26-2005 04:23 PM
weird MPlayer file problem GTBlackwell Linux - Software 1 02-16-2005 10:34 AM
A Really Weird File System Problem atheist Linux - Software 13 07-08-2004 03:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:19 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