in reply to backup for the users on the system in linux enviroment

You want to say "split /:/". Or use getpwent or User::pwent.

It also would be good idea to prepare an insert statement with "values (?,?,?...)" and provide the actual values as parameters to execute().

  • Comment on Re: backup for the users on the system in linux enviroment

Replies are listed 'Best First'.
Re^2: backup for the users on the system in linux enviroment
by hummty_dummty (Initiate) on Jun 18, 2007 at 00:47 UTC
    when i tried to use
    @columns = split /:/;

    i got the following errors
    Global symbol "$file" requires explicit package name at ./backup.pl li +ne 9. Global symbol "$file" requires explicit package name at ./backup.pl li +ne 11. Global symbol "@columns" requires explicit package name at ./backup.pl + line 18. Global symbol "@columns" requires explicit package name at ./backup.pl + line 20. Global symbol "@columns" requires explicit package name at ./backup.pl + line 21. Global symbol "@columns" requires explicit package name at ./backup.pl + line 22. Global symbol "@columns" requires explicit package name at ./backup.pl + line 23. Global symbol "@columns" requires explicit package name at ./backup.pl + line 24. Global symbol "@columns" requires explicit package name at ./backup.pl + line 25. Global symbol "@columns" requires explicit package name at ./backup.pl + line 26. Execution of ./backup.pl aborted due to compilation errors.

    you said "It also would be good idea to prepare an insert statement with "values (?,?,?...)" and provide the actual values as parameters to execute()."


    you mean i will change values in values('$username','$x','$userid','$groupid','$realname','$homedir','$shellpath')")
    to values(?,?,?,.....) ?
    thanx for your help
      Global symbol "$file" requires explicit package name at ./backup.pl li +ne 9.
      Put a use diagnostics; line at the beginning of your code, and you'll get a verbose explanation of this (or any other) message. Or look for the message in perldiag.
      you mean i will change values in values('$username','$x','$userid','$groupid','$realname','$homedir','$shellpath')") to values(?,?,?,.....) ?
      I mean do something like (example taken from biograd's scratchpad):
      # before your loop $sth_achroms = $dbh -> prepare( " INSERT INTO achroms (type, ac_id, length, chr_num, chr_strt, chr_end, bac_strt, bac_end, orient) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?) "); # later, inside your loop $sth_achroms -> execute( $achrom[0],$achrom[1],$achrom[2], $achrom[3], $achrom[4], $achrom[5], $achrom[6], $achrom[7], $achrom[8]);
      as far as those error messages go - you're using strict mode, but you're not declaring:
      my $file; my @columns;

        hello all monks finally i did it and i wrote that script tahnks for all who help me


        #!/usr/bin/perl -w use strict; use DBI; use diagnostics; #step1 - create connection objection . my $dsn = 'DBI:mysql:backupDB'; my $user = 'adam'; my $password = 'secret'; my $conn = DBI->connect($dsn,$user,$password) || die "Error connecting +" . DBI->errstr; my $file = "/etc/passwd"; open (han1, "$file") || die "error opening file: $!"; my @newrecords = <han1>; foreach (@newrecords) { my @columns = split /:/; my $username = $columns[0]; my $x = $columns[1]; my $userid = $columns[2]; my $groupid = $columns[3]; my $realname = $columns[4]; my $homedir = $columns[5]; my $shellpath = $columns[6]; $conn->do("insert into users(username,x,userid,groupid,realname,homedi +r,shellpath) values('$username','$x','$userid','$groupid','$realname' +,'$homedir','$shellpath')") || die "error preparing query" . $conn->e +rrstr; }

        the last thing i want to know is how can i make this operation updated i mean if i add new user for example how can i make the program to fetch the new records and add to the database