إعـــــــلان

تقليص
لا يوجد إعلان حتى الآن.

Perl Script -> Back up users

تقليص
X
 
  • تصفية - فلترة
  • الوقت
  • عرض
إلغاء تحديد الكل
مشاركات جديدة

  • Perl Script -> Back up users

    كود لعمل باك اب للمستخدمين من ملف etc/passwd

    شرح السكربت :

    1- إستدعاء ال DBI Library
    2 -عمل اوبجكت للكونكشن وهيتطلب منك 3 اشياء
    DBI ال Library الرئيسية ، و MySQL وهى نوع قاعدة البيانات و اسم الDataBase
    وال User name وال Password
    3 - عمل File handler لملف etc/passwd
    4- تخزين المحتوى فى array
    5- عمل Iteration على كل سطر وعمل Split لل Colons اللى بتفصل بين كل Column وتخزين كل واحد منها فى Variable
    6- تخزين كل عنصر خلال ال Iteration فى الداتا بيز بإستخدام Insert statment
    7-غلق ال File Handler


    كود:
     #!/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,homedir,shellpath) values('$username','$x','$userid','$groupid','$realname','$homedir','$shellpath')") || die "error preparing query" . $conn->errstr;
    close(han1);
    }
    التعديل الأخير تم بواسطة StrikerX; الساعة 19-06-2007, 02:46 AM.

  • #2
    شكرا لك على السكربت .
    انا ضفت شرح السكربت وغلق ال File handler لول ^^
    Programming-Fr34ks[dot]NET
    Ma Weblog
    ابدأ بتعلم Python | Ruby
    كتاب البايثون متوافر الآن
    لا اتواجد بهذا المنتدى ... للإتصال

    تعليق


    • #3
      شكرا Black ice علي الاسكربت وان شاء الله نشوف المزيد من الاسكربتات

      تعليق


      • #4
        لا شكر على واجب وباذن الله ساقوم بالافاده على قدر المستطاع وشكرا للقائمين على هذا المنتدى

        تعليق


        • #5
          تسلم يا باشا على السكريبت
          GCS

          تعليق


          • #6
            تسلم ايديك ياباشا عايزين كمان من الحاجات الحلوه ديت
            BOOOF , I AM GONE
            Still , you gotta wait for my PRESENT :D
            C programming arabic Tutorial|Programming-fr34ks

            تعليق

            يعمل...
            X