Hi monks
I am tring to open the remote file from remote host by
using Net::Telnet module,i suceeded in that.But my actual
task is to develop a script which should opens the file and it internally checks the perticular username is present,
if that user name is not there means,i have to pass the username and other parameters from the commandline.

Below is my code and also the remote file format
that i have to append.

#!/usr/bin/perl -w $arg=$ARGV[0]; $arg1=$ARGV[1]; $prompt = "bash-2.03\#"; #print "$prompt\n"; use Net::Telnet; $telnet = new Net::Telnet(Timeout=>10,prompt=>"/$prompt/i",Errmode=>'d +ie'); $telnet->open("xxx.xx.xxx.xxx"); $telnet->waitfor('/login: $/i'); $telnet->print('xxxx'); $telnet->waitfor('/password: $/i'); $telnet->print('xxxxxx'); $telnet->waitfor("/$prompt/i"); @arr=$telnet->cmd('cat aa.txt'); foreach(@arr) { @arr1=split/:/,$_; if($arr1[0]=~/$arg/) { print"user exist\n"; } else { @arr=push @arr,$arg1; print @arr; } } print @arr;
#remote file format that i have to append.<br> <fileformat> root:x:0:1:Super-User:/:/usr/bin/bash daemon:x:1:1::/: bin:x:2:2::/usr/bin: chan sys:x:3:3::/: adm:x:4:4:Admin:/var/adm: lp:x:71:8:Line Printer Admin:/usr/spool/lp: chan uucp:x:5:5:uucp Admin:/usr/lib/uucp: nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico listen:x:37:4:Network Admin:/usr/net/nls: nobody:x:60001:60001:Nobody:/: noaccess:x:60002:60002:No Access User:/: nobody4:x:65534:65534:SunOS 4.x Nobody:/: sundarab:x:11301:237:Sundara BHARATHI:/home/users/sundarab:/bin/ksh andccadm:x:11351:237:ANDDSLAM CC Admin:/home/users/andccadm:/bin/ksh drobrech:x:11354:237:Dirk ROBRECHTS:/home/users/drobrech:/bin/ksh vponnach:x:11321:237::/home/users/vponnach:/bin/ksh krobert:x:11356:237:Kim Robertson:/home/users/krobert:/bin/ksh mamir:x:11357:237:Malik Amir:/home/users/mamir:/bin/ksh dcornfie:x:11358:237:Damian Cornfield:/home/users/dcornfie:/bin/ksh herbruge:x:11359:237:Eddy Van Herbruggen:/home/users/herbruge:/bin/ksh wiesem:x:11360:237:Marc WIESE:/home/users/wiesem:/bin/ksh matheeum:x:11361:237:Maurice MM MATHEEUSSEN:/home/users/matheeum:/bin/ +ksh borremak:x:11362:237:Kris BORREMANS:/home/users/borremak:/bin/ksh bekaerte:x:11363:237:Emmanuel BEKAERT:/home/users/bekaerte:/bin/ksh hoofp:x:11364:237:Patrick VAN HOOF:/home/users/hoofp:/bin/ksh straetri:x:11365:237:Rik VERSTRAETE:/home/users/straetri:/bin/ksh ayazt1:x:11366:237:Tamer AYAZ:/home/users/ayazt1:/bin/ksh denbroep:x:11367:237:Philippe VAN DEN BROEK:/home/users/denbroep:/bin/ +ksh aertsb:x:11368:237:Bert AERTS:/home/users/aertsb:/bin/ksh hermanjo:x:11369:237:Johan HERMANS:/home/users/hermanjo:/bin/ksh
the above script will opens the file from remote server,
after that i parsed the first field of each line i.e
user name,when i run this script with existing user name as argument it prints "username exist",if the argument not
matches with the existing username,then it should append
the file with that argument at remote host. keep pouring your ideas.

In reply to How to append the remote file by using Net::Telnet module by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.