Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells, Users and Groups

Count users with “last”

Submitted by on November 19, 2005 – 11:15 pm 5 Comments

Here is a quick example showing how to count users logged in on a particular date using the “last” command on Linux.

last | awk '/bold/ {printf ("%st%s    t%s%sn", $1,$3,$5,$6)}' | uniq | grep -c "Aug 15"
Print Friendly, PDF & Email

5 Comments »

  • Sonny says:

    Hi there,
    I’m learning C++ from Cay Horstmann’s “Big C++”, and I stumbled upon the following code:

    #include
    #include

    using namespace std;

    int main()
    {
    cout <> first;
    cin >> middle;
    cin >> last;
    string initials = first.substr(0,1) + middle.substr(0,1) + last.substr(0,1);
    cout << "Your initials are " << initials << "n";

    return 0;
    }

    If I begin middle name with one or more white-spaces, the output does not change. Is this because the .substr begins count only with the first non-whitespace character? For example, if we have the name John David Smith, and I enter,
    John
    David
    Smith

    the output is JDS regardless of whether I type David with or without space before it. This puzzles me. I know that space characters count between two or more words in a string (Hello, World!n consists of 14 characters total, since the space between the comma and the W is counted). But if I enter a string that begins with a white-space, and I ask .substr to begin count from character 0, does it disregard the space and jump to the first letter?
    Any clarification would be greatly appreciated. Thank you!

  • Ed D says:

    Here is my code. I need help figuring out how to get a total of credit hours taken after the user is prompted to add more and to keep adding them together so in the end i can add them to the intital credit hours asked for in the very beginning.

    Please help. Thank you

    #include
    #include

    using namespace std;

    int main()

    {
    string classstanding, answer;

    int studentid, credits, points , addcredits, usernum, totalcredits, grade ;
    float intgpa;

    cout <> answer;

    while ( answer == “y” )
    {

    cout <> studentid;

    cout <> credits;

    cout <> points;

    if(credits >= 90)
    {
    classstanding = “Senior”;
    }
    else if (credits >= 60)
    {
    classstanding = “Junior”;
    }
    else if (credits >= 30)
    {
    classstanding = “Sophmore”;
    }
    else if (credits >= 0)
    {
    classstanding = “Freshman”;
    }
    else
    {
    classstanding = “Error”;
    }

    intgpa = ( points / credits ) ;

    cout <> answer ;

    while ( answer == “y” )
    {

    cout <> addcredits ;

    totalcredits = addcredits + credits;

    cout << endl <> answer ;

    }

    cout << endl <<endl << endl << "Student: " << studentid << endl;

    cout << "nGrade Level: "<< classstanding << "tCredits : "<< credits << "tPoints : " << points << "tGPA : " << intgpa
    << endl << totalcredits ;

    cout << endl << "*************************************************************" << endl ;

    cout <> answer;

    }

    }

  • Con Orpe says:

    After customer filling the form, the form data will be send to mysql, and an email will sent to me with the last form data that customer submitted. All is working, but only the problem is in the email “last mysql data” is not going as inline text. So, how to do this? I am doing in PHP. In am new in PHP. Please help me.

    See full code – http://halmiratea.com/to-stackoverflow.com-not-personal1.php#problem

    <?php

    define('DB_NAME', 'sandi565_form11');
    define('DB_USER', 'XXXXXXX');
    define('DB_PASSWORD', 'XXXXXXX');
    define('DB_HOST', 'localhost');

    $link = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);

    if (!$link) {
    die('Could not connect: ' . mysql_error());
    }

    $db_selected = mysql_select_db(DB_NAME, $link);

    if (!$db_selected) {
    die('Can't use ' . DB_NAME . ': ' . mysql_error());
    }

    //Start Posting the data in Mysql database from Form Input

    $value = $_POST['input1'];
    $value2 = $_POST['MAmount'];

    $sql = "INSERT INTO demo (input1, MAmount) VALUES ('$value', '$value2')";

    if (!mysql_query($sql)) {
    die('Error: ' . mysql_error());

    }

    //start print the database

    $data = mysql_query("SELECT * FROM demo ORDER BY ID DESC LIMIT 1")
    or die(mysql_error());
    Print "”;
    while($info = mysql_fetch_array( $data ))
    {
    Print “”;
    Print “ID: “.$info[‘ID’] . ” “;
    Print “Input1: “.$info[‘input1’] . ” “;
    Print “MAmount: “.$info[‘MAmount’] . ” “;
    }
    Print “”;

    mysql_close();

    //end print the database on form processing page

    //start emailing the data

    date_default_timezone_set(‘Asia/Kolkata’);

    require_once(‘class.phpmailer.php’);
    //include(“class.smtp.php”); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail = new PHPMailer();

    //$body = “gdssdh”;
    //$body = preg_replace(“[]”,”,$body);

    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host = “ssl://XXXXXXX.XXXXXXX.org”; // SMTP server
    $mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
    // 1 = errors and messages
    // 2 = messages only
    $mail->SMTPAuth = true; // enable SMTP authentication
    $mail->SMTPSecure = “ssl”; // sets the prefix to the servier
    $mail->Host = “XXXXXXX.XXXXXXX.org”; // sets GMAIL as the SMTP server
    $mail->Port = 465; // set the SMTP port for the GMAIL server
    $mail->Username = “contact@XXXXXXX.com”; // GMAIL username
    $mail->Password = “XXXXXXX”; // GMAIL password

    $mail->SetFrom(‘contact@XXXXXXXX.com’, ‘HAL’);

    //$mail->AddReplyTo(“user2@gmail.com’, ‘First Last”);

    $mail->Subject = “Halmira 469”;

    //THE PROBLEM IS HERE WHEN I WANT TO SEND THE DATA AS INLINE TEXT TO EMAIL FROM MYSQL IT IS NOT WORKING. ONLY “PRINT THE DATA” IS SENDING TO EMAIL.

    $body = ‘Print the data’;
    mysql_connect(“localhost”,”XXXXXXX”,”XXXXXXX”);
    @mysql_select_db(“sandi565_form11”);
    $query[“SELECT * FROM demo ORDER BY ID DESC LIMIT 1”];
    $result = mysql_query($query);

    //while ($row = mysql_fetch_array ($result)) {
    // $mail->AltBody = “To view the message, please use an HTML compatible email viewer!”; // optional, comment out and test
    $mail->MsgHTML($body);
    $address = “XXXXXXX@gmail.com”;
    $mail->AddAddress($address, “user2”);

    //$mail->AddAttachment(“images/phpmailer.gif”); // attachment
    //$mail->AddAttachment(“images/phpmailer_mini.gif”); // attachment

    if(!$mail->Send()) {
    echo “Mailer Error: ” . $mail->ErrorInfo;
    } else {
    echo “Message sent!”;
    }

    ?>

  • Adam says:

    ok iv had the Nikon Coolpix s550 10 MP digital camera for bout a year and a half. Every time i use the movie mode on it, it always cuts the lst two seconds of sound off of the video. Idk why. it has been pretty annoying in recent times, but i dnt use movie mode that often so it isnt that bad for me. im just wondering why it cuts off the last 2 sec of sound when all their other cameras dont do this. if anyone has insight on this or a fix for it, lemme kno.

  • Jon P says:

    i’m trying to get the PK of the last record from a table. the catch is, the PK is not auto_incremented. it’s something like A1 where A is the user type (can be A, P, or S) and 1 is the part that is auto_incremented. in case you’re wondering why it’s like that, it was required of us to do it this way. i can’t use ORDER BY id DESC LIMIT 1 because it doesn’t return the PK of the last record. is there a way to do this?

Leave a Reply

%d bloggers like this: