LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to truncate a file and disconnect a session ! (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-truncate-a-file-and-disconnect-a-session-836682/)

shipon_97 10-07-2010 01:29 AM

How to truncate a file and disconnect a session !
 
Dear Friends,

I have two questions :

1) Is it possible to truncate the file content , not to drop the file ? i.e, I want to just delete a file's content only, not to drop the file .

2) I can find the connectd user using command 'w' or 'who' . Now How can I force disconnect a session from the list of 'w'/'who' command ?

Waiting for kind reply ... ...

prayag_pjs 10-07-2010 01:51 AM

Code:

1. echo > file1
2. If user is connected via ssh :
Quote:

Do "kill <pid>" where pid is any process from their session (found by typing 'w')
ps -ax to find the pid of the sshd session, and kill it.
Code:

for i in `ps aux | grep user | grep -v grep | awk '{print $2}'`; do kill -9 $i; done;


All times are GMT -5. The time now is 11:21 AM.