Advertisement
Guest User

Untitled

a guest
May 15th, 2013
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.44 KB | None | 0 0
  1. #!/usr/local/bin/perl
  2. #Simple script to change the hostname with PcLinuxOs.
  3. #Of course you must be logged as root.
  4.  
  5. #ATTENTION: this program is free software, so it came with _ABSOLUTE_
  6. #NO WARRANTY! I'm not responsable if this software erase your hard disk,
  7. #empty your bank account, stole your car, destroy your furnitures, set
  8. #your house in fire, seduces your wife and kill your dog.
  9.  
  10. print "To change the hostname you must be logged as root.\n";
  11. RESTART:        #Here is the Label to restart the selection of hostname if user use spaces...
  12. print "Choose your hostname:
  13. (You can't choose name with spaces)\n";
  14. $hostname=<STDIN>;
  15. chomp($hostname);
  16. $hostname =~ s/^\s+//;      #Remove all spaces before the hostname
  17. if($hostname =~ s/\s//g)    #Check for some spaces in the hostname
  18.     {
  19.     print "I told you that you can't choose name with spaces!\n";
  20.     goto RESTART;       #Yes, I know I shouldn't use goto...
  21.     }
  22. else
  23.     {
  24.     print "You chose $hostname\n";
  25.     }
  26. $file1="/etc/sysconfig/network";
  27. open(FILE1,">$file1") or die "Error! Can't open the file:\n$file1\n";
  28. print FILE1 "HOSTNAME=$hostname
  29. NETWORKING=yes
  30. CRDA_DOMAIN=US";
  31. close(FILE1);
  32. $file2="/etc/hosts";
  33. open(FILE2,">$file2") or die "Error! Can't open the file:\n$file2\n";
  34. print FILE2 "# generated by drakconnect
  35. 127.0.0.1 $hostname localhost.localdomain localhost";
  36. close(FILE2);
  37. print "Your hostname will be changed at the next reboot.
  38. Now you can continue to watch Porn or do whatever you want!\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement