LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-18-2010, 04:37 AM   #1
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Rep: Reputation: 18
delete a file


Hi
can someone help me delete a file on a remote server using shell scripting
.
 
Old 07-18-2010, 04:43 AM   #2
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
common idea would be to use ssh with the delete command like
Code:
ssh [user]@[host] rm -f path/to/file
If this doesn't suit your scenario, you should explain it further
 
Old 07-18-2010, 05:38 AM   #3
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Original Poster
Rep: Reputation: 18
thanx Zirias
it prompts for password , i dont want to have a passwordless ssh login
how can i supply the password with this command
i tried using expect and send command but it doesnt work
 
Old 07-18-2010, 05:44 AM   #4
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
Hmm, you'll probably want to use an ssh key. You can generate one for your script, make it have no passphrase and keep it secret by setting appropriate permissions on it.

See ssh-keygen(1).
 
Old 07-18-2010, 05:46 AM   #5
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Original Poster
Rep: Reputation: 18
this will create a ssh login with out password which is not my requirement
i need to somehow pass the password alsong with the ssh command
 
Old 07-18-2010, 06:05 AM   #6
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
No it won't, as long as you keep THAT key secret. Passing the password is NOT a good idea, using a key is much more secure.
 
1 members found this post helpful.
Old 07-18-2010, 06:34 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

Quote:
Originally Posted by fernfrancis View Post
this will create a ssh login with out password which is not my requirement
i need to somehow pass the password alsong with the ssh command
ssh and scp do not have an option to pass the password automatically. That is part of the security mechanism ssh enforces.

As already stated by zirias: Setting up a password-less ssh is the way to go. Much more secure.

Hope this helps.
 
1 members found this post helpful.
Old 07-25-2010, 02:53 AM   #8
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Original Poster
Rep: Reputation: 18
i did want zirias suggested used the command

ssh [user]@[host] rm -f path/to/file

now it gives me permission denied
the file resides in /home/XYZ/t/txt
 
Old 07-25-2010, 03:00 AM   #9
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
Well that probably relates to filesystem permissions. Who is creating the file? Log in the machine interactively, check the permissions with ls -l. You need to add your ssh key to an account that actually HAS permissions for the file you want to delete AND the directory containing that file.
 
Old 07-25-2010, 04:28 AM   #10
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Original Poster
Rep: Reputation: 18
i logged and tried to delete it manually it gives the same permission denied , i checked the ownership group and permission it, owner itself cant delete the file how is this possible..
 
Old 07-25-2010, 04:34 AM   #11
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,
Quote:
i logged and tried to delete it manually it gives the same permission denied , i checked the ownership group and permission it, owner itself cant delete the file how is this possible..
Can you post the output of stat /home/XYZ/t/txt and ls -la /home/XYZ/t/ (as root user).

Last edited by druuna; 07-25-2010 at 04:39 AM. Reason: Must be done as root
 
1 members found this post helpful.
Old 07-25-2010, 04:41 AM   #12
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Original Poster
Rep: Reputation: 18
stat output

File: `aabackup.zip'
Size: 14158138 Blocks: 27704 IO Block: 4096 regular file
Device: 805h/2053d Inode: 50069506 Links: 1
Access: (0777/-rwxrwxrwx) Uid: ( 502/ francis) Gid: ( 502/ francis)
Access: 2010-07-25 09:31:01.000000000 +0400
Modify: 2010-07-25 03:59:22.000000000 +0400
Change: 2010-07-25 13:18:04.000000000 +0400


ls -la output
-rwxrwxrwx 1 francis francis 14158138 Jul 25 03:59 aabackup.zip
 
Old 07-25-2010, 04:52 AM   #13
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

I asked for the output of ls -la /home/XYZ/t/, not ls -la /home/XYZ/t/txt

PS: I'm off-line for a few hours, answer will take a while.
 
Old 07-25-2010, 05:11 AM   #14
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
Quote:
Originally Posted by druuna View Post
I asked for the output of ls -la /home/XYZ/t/
I guess you want to see the permissions of the directory, so, better make this ls -lad /home/XYZ/t
 
0 members found this post helpful.
Old 07-25-2010, 05:57 AM   #15
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 229

Original Poster
Rep: Reputation: 18
thanx solved the directoy had root permissions
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
file from install ffmpeg conflicts w/file from package fmpeg-libs: which to delete? ybalazs Linux - Software 0 10-27-2009 01:21 AM
Upload file to ftp server -vsftp- but can not delete or change the file once uploaded murattas6 Linux - Server 2 06-26-2009 06:00 AM
how to delete last number/word of a file and incude file count at the end of the chennaiguy Linux - Newbie 2 02-18-2008 09:08 PM
Tried to delete file as root but it says I don't have permission to delete it! beejayzed Mandriva 23 03-12-2004 02:46 AM


All times are GMT -5. The time now is 10:20 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration