Ric Posted September 17, 2004 Report Share Posted September 17, 2004 Hi I hope some one can help me, I use a perl script to make logon scripts for my samba domain, #! /usr/bin/perl # Generate a custom logon script when a user # logs into the network open LOGON, ">/home/share/netlogon/$ARGV[0].bat"; print LOGON "\@echo on \r\n"; print LOGON "IF EXIST F: NET USE F: /DELETE /y\r\n"; print LOGON "IF EXIST H: NET USE H: /DELETE /y\r\n"; print LOGON "IF EXIST I: NET USE I: /DELETE /y\r\n"; print LOGON "IF EXIST J: NET USE J: /DELETE /y\r\n"; print LOGON "IF EXIST T: NET USE T: /DELETE /y\r\n"; print LOGON "IF EXIST S: NET USE S: /DELETE /y\r\n"; print LOGON "IF EXIST R: NET USE R: /DELETE /y\r\n"; print LOGON "IF EXIST K: NET USE K: /DELETE /y\r\n"; print LOGON "IF EXIST V: NET USE V: /DELETE /y\r\n"; print LOGON "IF EXIST W: NET USE W: /DELETE /y\r\n"; print LOGON "IF EXIST U: NET USE U: /DELETE /y\r\n"; print LOGON "IF EXIST X: NET USE X: /DELETE /y\r\n"; print LOGON "IF EXIST F: NET USE F: /DELETE /y\r\n"; print LOGON "NET TIME \\\\$ARGV[1] /SET /YES\r\n"; # print LOGON "NET USE H: /HOME\r\n"; print LOGON "NET USE I: \\\\$ARGV[1]\\Students\r\n"; print LOGON "NET USE J: \\\\$ARGV[1]\\Learning\r\n"; # print LOGON "NET USE T: \\\\$ARGV[1]\\Applications\r\n"; # print LOGON "NET USE S: \\\\$ARGV[1]\\BootImages\r\n"; print LOGON "NET USE R: \\\\$ARGV[1]\\applications\r\n"; if ($ARGV[2] eq "teachers") { print LOGON "NET USE K: \\\\$ARGV[1]\\Teachers\r\n"; print LOGON "NET USE V: \\\\$ARGV[1]\\AdminStudents\r\n"; } if ($ARGV[2] eq "admin") { print LOGON "NET USE K: \\\\$ARGV[1]\\Teachers\r\n"; print LOGON "NET USE V: \\\\$ARGV[1]\\AdminStudents\r\n"; print LOGON "NET USE W: \\\\$ARGV[1]\\AdminTeachers\r\n"; } # print LOGON "deltree /y c:\\windows\\profiles\\* \r\n"; print LOGON "if not \"%OS%\"==\"Windows_NT\" GOTO NT9x\r\n"; print LOGON ":NTOS\r\n"; print LOGON "echo \"Windows NT\"\r\n"; print LOGON "echo printers\r\n"; print LOGON "\\\\$ARGV[1]\\netlogon\\con2prt.exe /f\r\n"; print LOGON "regedit /s printerpatch.reg\r\n"; print LOGON "logonprinters.vbs\r\n"; print LOGON "NET USE H: \\\\$ARGV[1]\\$ARGV[0]\r\n"; print LOGON "GOTO END\r\n"; print LOGON ":NT9x\r\n"; print LOGON "echo \"Windows 9x\"\r\n"; print LOGON "if exist \"c:\\WINDOWS\\PROFILES\\\" deltree /y c:\\windows\\profiles\\*\r\n"; print LOGON "NET USE H: /HOME\r\n"; print LOGON "if not exist c:\\windows\\proguard.exe copy \\\\$ARGV[1]\\Netlogon\\ProGuard.exe c:\\windows\r\n"; print LOGON "del c:\\windows\\*.pwl\r\n"; print LOGON "c:\\windows\\proguard.exe\r\n"; print LOGON "R:\\packages\\INTERCHK\\W95Inst\\setup -inl -a\r\n"; print LOGON "start /wait r:\\packages\\INTERCHK\\Savagent.exe -update -poll=3600\r\n"; print LOGON "GOTO END\r\n"; print LOGON ":END\r\n"; print LOGON "echo \"DONE!!\"\r\n"; print LOGON "EXIT\r\n"; # print LOGON "pause\r\n"; close LOGON; This all works very well however i now want to be able to test which lab a machine is in the machines are all names lab1-01, lab1-02, lab2-01 etc. now to the question does anyone know how i can do a 'if' command that only looks at the 1st 5 letters of the machine name (the lab1 bit) The machine name is passed to the script as $ARGV[3] hope that makes sense regards Ric Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted September 18, 2004 Report Share Posted September 18, 2004 (edited) use Switch; $val = substr($ARGV[3], 0, 5); switch ($val) { case "lab1-" { <<do something>> } case "lab2-" { <<do something else>> } else { print "There was no input" } } Edited September 18, 2004 by Steve Scrimpshire Quote Link to comment Share on other sites More sharing options...
papaschtroumpf Posted September 19, 2004 Report Share Posted September 19, 2004 use Switch; $val = substr($ARGV[3], 0, 5); switch ($val) { case "lab1-" { <<do something>> } case "lab2-" { <<do something else>> } else { print "There was no input" } } <{POST_SNAPBACK}> that'w one way to do it, ther are probably 3646753223457598 other ways to do it. Welcome to Perl :P Quote Link to comment Share on other sites More sharing options...
Ric Posted September 20, 2004 Author Report Share Posted September 20, 2004 Thanks i will give that a try Ric Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.