How to remove user accounts that are old via cronjob


Recommended Posts

At work I've set up a Ubuntu server running 9.10, and open SSH installed. I've got it set up that I can run a script to add new users to the system, and when they log in using WINSCP or Filezilla on port 22, they get put into their own jailed shell, or chroot or whatever...they can only see files in their designated folder and nothing else.

My boss has asked a way to clean up old accounts from the system however, and I don't see a way to do this (I am not strong in shell scripting or unix/linux period). Since users don't actually log into the server, just ssh in, running "last" does not tell me when they were last on. Instead, I would have to refer to the auth.log files to see when users were SSH'd in. What I need to try to do is find some way to grep through the file, and find which users last logged in more than say, 30 days ago. If a users name was not seen in 30 days, or the last entry had a timestamp 30 days or older, then a script would pass that username to a deluser command to remove their account from the system.

Is there an easy way to do this? I don't mind doing it by hand, however it would be nicer to have some kind of automated system to delete these things (I already have a script that deletes files uploaded more than 2 weeks ago).

Thanks!

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Then why are you still here?  
    • Glary Utilities 6.44.0.48 by Razvan Serea Glary Utilities offers numerous powerful and easy-to-use system tools and utilities to fix, speed up, maintain and protect your PC. Glary Utilities allow you to clean common system junk files, as well as invalid registry entries and Internet traces. You can manage and delete browser add-ons, analyze disk space usage and find duplicate files. You can also view and manage installed shell extensions, encrypt your files from unauthorized access and use, split large files into smaller manageable files and then rejoin them. Furthermore, Glary Utilities includes the options to find, fix, or remove broken Windows shortcuts, manage the programs that start at Windows startup and uninstall software. All Glary Utilities tools can be accessed through an eye-pleasing and totally simplistic interface. Glary Utilities 6.44.0.48 changelog: Optimized Context Menu Manager: Improved features based on user feedback. Optimized Wipe Free Space: Optimized the interface display for a better user experience. Minor GUI improvements. Minor bug fixes. Download: Glary Utilities 6.44.0.48 | 27.0 MB (Freeware) Download: Portable Glary Utilities | 32.3 MB View: Glary Utilities Homepage | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • why to touch this audio corpse? use aimp
    • i got a better prices on reddit /homelabsales. same drives for $80 less
  • Recent Achievements

    • Reacting Well
      Juan Dela earned a badge
      Reacting Well
    • Week One Done
      Collagen Project earned a badge
      Week One Done
    • Reacting Well
      Wakeen1966 earned a badge
      Reacting Well
    • Rookie
      Almohandis went up a rank
      Rookie
    • Apprentice
      jahara21 went up a rank
      Apprentice
  • Popular Contributors

    1. 1
      +primortal
      514
    2. 2
      +Edouard
      266
    3. 3
      PsYcHoKiLLa
      146
    4. 4
      Steven P.
      96
    5. 5
      macoman
      54
  • Tell a friend

    Love Neowin? Tell a friend!