LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   delete a file (https://www.linuxquestions.org/questions/linux-newbie-8/delete-a-file-820482/)

fernfrancis 07-18-2010 04:37 AM

delete a file
 
Hi
can someone help me delete a file on a remote server using shell scripting
.

zirias 07-18-2010 04:43 AM

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 :)

fernfrancis 07-18-2010 05:38 AM

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

zirias 07-18-2010 05:44 AM

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).

fernfrancis 07-18-2010 05:46 AM

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

zirias 07-18-2010 06:05 AM

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.

druuna 07-18-2010 06:34 AM

Hi,

Quote:

Originally Posted by fernfrancis (Post 4036972)
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.

fernfrancis 07-25-2010 02:53 AM

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

zirias 07-25-2010 03:00 AM

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.

fernfrancis 07-25-2010 04:28 AM

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..

druuna 07-25-2010 04:34 AM

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).

fernfrancis 07-25-2010 04:41 AM

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

druuna 07-25-2010 04:52 AM

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.

zirias 07-25-2010 05:11 AM

Quote:

Originally Posted by druuna (Post 4044612)
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 :)

fernfrancis 07-25-2010 05:57 AM

thanx solved the directoy had root permissions


All times are GMT -5. The time now is 03:48 AM.