Visit Our UNIX and Linux User Community

Script to eliminate files .rlogin

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to eliminate files .rlogin
# 1  
Old 06-24-2011
Script to eliminate files .rlogin

Hi guys, I'm try making to script for eliminate files rlogins.
for i in `cat /etc/passwd |awk -F: '{print $6}'`; do
    if test "$i" = "$path1"; then
    echo $i
    cd $i
         if [ -f .rhosts ]; then
               echo "$i/.rhosts detectado"|mail -s "rhosts" root
               rm -f $i/.rhosts

I want my script only check users with path in /home/*, but the symbol "*" is not working.

As I can do to make the command "test" compare the path "$ i" with a path / home / * (ie / home / all users)

Any suggestions?


# 2  
Old 06-24-2011
* doesn't work in quotes. Even if it did, that's probably not where you'd want to put it.

You also have several useless uses of cat and backticks.

You don't need to cd into each and every individual home directory either. And if you do, you should really cd back out after, or you won't be able to cd into anything else under /home/ after. If you're going to use awk, you might as well check for /home inside it too.

awk -v FS=':' '($6 ~ /^\/home/)' < /etc/passwd | 
while read USERNAME G G G G H G
        if [ -f "$H/.rhosts ]
                echo "$H/.rhosts detectado" | mail -s "rhosts" root
                rm -f "$H/.rhosts"

Last edited by Corona688; 06-24-2011 at 02:39 PM..
# 3  
Old 06-24-2011
*?[0-9] will not glob inside any sort of quotes (or if there is no compatible target, the globbing characters persist). test = does not glob BTW, [ is test is a shell builtin for more advanced shells.

Why not simplify:
for f in /home/*/.rhosts
 if [ "$f" = "/home/*/.rhosts" ]

# 4  
Old 06-24-2011
A parody of your script but using grep in a pipeline to select lines starting with /home/ . Using "while read" avoids the "for .... in open-ended-list" syntax which is notorious for generating command lines which are too long.

awk -F: '{print $6}' /etc/passwd | grep "^\/home\/" | while read home_dir
         if [ -f ${home_dir}/.rhosts ]; then
               echo "${home_dir}/.rhosts detectado"|mail -s "rhosts" root
               rm -f ${home_dir}/.rhosts

# 5  
Old 06-24-2011
Hey thanks!!!!


for H in /home/*
        if [ -f "$H/.rhosts" ];
                echo "$H/.rhosts detectado"|mail -s "rhosts" root
                rm -f $H/.rhosts

# 6  
Old 06-24-2011
.shosts for ssh has a similar layout, but I am not sure it does much, since for the good life you need to make and distribute keys, but you might just rename them .shosts or .rhosts_not_allowed.

As prevention, on all accounts, why not put a root owned file readable not writable at the original .rhosts name with a message inside.
# 7  
Old 06-24-2011
Permissions 600 and owner "root" are correct and preferred permissions for all ".rhosts" files.

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help to eliminate the records

Hi All, Please help me how to remove the records from the file if it is having more number of fields than the required one, before loading into stage Here is the sample records. File is space delimited one chandu 1121324 CC ( 2 spaces) chandu balu 434657 DD (3 spaces) -- failing due to... (10 Replies)
Discussion started by: bbc17484
10 Replies

2. Shell Programming and Scripting

How to eliminate ^L

Hi, I am trying to create a text file from data retrieved from a query.The data retrieved is having this character '^L' at regular intervals of the data. How can i eliminate this, Please find below the sample data. I tried sed -e "s/\^L//g" to convert it, but with no luck ^LCODE*SERIAL... (11 Replies)
Discussion started by: ramkiran77
11 Replies

3. Shell Programming and Scripting

rlogin and script

I am writing a script to do rlogin to another system and execute commands on the remote system, i can successfully login to the remote system but the commands are not sent. i can only use rlogin to get to the remote system. what can i do? (6 Replies)
Discussion started by: aydj
6 Replies

4. Shell Programming and Scripting

script to eliminate left and right fields and to get the ouput.

Hi Experts, I have a file as given below and want to filter out the filenames in it , by deleting left and right filds and to have the fllenames (There are spaces in the filename), Sun Jan 11 11:20:10 2009 1 0 /home/output/file2311_recent.list user1 user2 0 done Sun Jan 11 11:20:10 2009 1 0... (10 Replies)
Discussion started by: rveri
10 Replies

5. Shell Programming and Scripting

Shell script help to eliminate files of todays date

Hi I am very new to shell scripting and have written a script (below). However the directory I am searching will contain a file with a .trn extension each day which I want to eliminate. Each day the file extension overnight will change to trx, if this fails I want to know. Basically what I... (2 Replies)
Discussion started by: richM
2 Replies

6. Shell Programming and Scripting

script for nested rlogin and telnet

I want to write a script that rlogins to a couple machines and then from the last machine, telnet into a final machine and execute a command. So in pseudocode it would look like: rlogin host1 from host1 rlogin host2 from host2 telnet host3 from host 3 execute command The reason for the... (6 Replies)
Discussion started by: mcburke38
6 Replies

7. Shell Programming and Scripting

rlogin inside a c-shell script

Hi Forumers, Sorry if it's really simple, but I couldn't find a way out. :( I've to do something like this in a script (csh): <some commands, variable settings, scripts> rlogin different_server <some commands, variable settings, scripts> After "rlogin", it shows the prompt of the... (5 Replies)
Discussion started by: sumitgarg
5 Replies

8. Shell Programming and Scripting

Eliminate variable checking in a script

RH Linux, $SHELL=/bin/ksh I have a .profile which I source in as such --> . .profile Whats happening is the variables are getting validated and generating errors. for example .profile export foo=/to/the/moon when I . .profile , I get : not foundmyusername/.profile or bad... (8 Replies)
Discussion started by: BMetelsky
8 Replies

9. Shell Programming and Scripting

How to Eliminate first line of multiple files

hi gurus ,, I have multiple files with same file a particular directory for ex: file20061101.trf file20061102.trf file20061103.trf Each of the file has a header as column names.. My questions is how can i eliminate the first row of each of these... (11 Replies)
Discussion started by: sish78
11 Replies

10. Shell Programming and Scripting

rlogin from Shell script

I am logged into an AIX Unix box. From there I want to remotely login to remotely login to an HP-UX Unix box and want to execute a command that will create a file. I want to get the file to the AIX box. Can someon eplease advise how to automate that in a shell script? At the first step I want to... (2 Replies)
Discussion started by: asutoshch
2 Replies

Featured Tech Videos