Linux question of the day

124678

Comments

  • paul78paul78 Member Posts: 3,016 ■■■■■■■■■■
    Yeah - I didn't know the answer either so I didn't want to totally give it away - icon_wink.gif

    But I will admit that I cheated and looked at the bash source code and saw it as an available redirect device. icon_redface.gif
  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    paul78 wrote: »
    Oh - how cool - I didn't know bash had a builtin tcp device file. Good one.
    *thumbs up* I like your subtle hint :)
    Glad you enjoyed the challenge
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    onesaint wrote: »
    it's not apparent unless you've read about it someplace
    Yes, it is true for this question, although comments show that some fellow TEers took on the challenge and did "original research" (citation needed).

    :)
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    onesaint wrote: »
    Great reference thread and question!
    Great thought-provoking question again, @ChooseLife.
    Thank you, fellas. Your feedback motivates me to make the effort to come up with interesting questions...
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • UnixGuyUnixGuy Mod Posts: 4,564 Mod
    I had to search for answers for the last few questions, good job guys :)

    New question...

    Q) We have a script called "backup.sh", we need to schedule it to run at 10:00 pm every 4th Saturday of every month. How can we do that?
    Certs: GSTRT, GPEN, GCFA, CISM, CRISC, RHCE

    Check out my YouTube channel: https://youtu.be/DRJic8vCodE 


  • log32log32 Users Awaiting Email Confirmation Posts: 217
    Three approaches to achieve this in my opinion.
    1) in crontab, 0 22 24-31 * 6 backup.sh
    2) edit the script to check for the current day and if it matches the last Saturday of the month only then it gets executed.
    3) create a crontab with the && operator, the first script checks for hte last day of Saturday, if it succeeds, then the other script gets executed. e.g. :
    00 22 24-31 * 6 check_for_saturday.sh && backup.sh
  • UnixGuyUnixGuy Mod Posts: 4,564 Mod
    @log32:

    Now this is the trick. This is a common mistake:

    00 22 24-31 * 6 <== this will execute every Saturday (because day of the week = 6) AND everyday in the range 24-31 ! So this will execute whenever any criteria is met, rather than executing in a mutual exclusive manner.

    So this will execute every Saturday and every Sunday, Monday, Tuesday , Wednesday,..etc in the range 24-31
    Certs: GSTRT, GPEN, GCFA, CISM, CRISC, RHCE

    Check out my YouTube channel: https://youtu.be/DRJic8vCodE 


  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    UnixGuy, that's a good one. As I understand, log32's solutions #2 and #3 are the right answer, but if you know a better trick, please do share!
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • onesaintonesaint Member Posts: 801
    I think I would do a combination of cron and scripting. Maybe run the cron job daily and do a date check to see if the current date is a Saturday (date --date="Saturday") then check if the current date is within the last 7 days of the month (with cal maybe?). If it is, execute the rest of the script, if not, exit.
    Work in progress: picking up Postgres, elastisearch, redis, Cloudera, & AWS.
    Next up: eventually the RHCE and to start blogging again.

    Control Protocol; my blog of exam notes and IT randomness
  • UnixGuyUnixGuy Mod Posts: 4,564 Mod
    @ChooseLife:

    They will work but not always. From 22-31, what if there are two Saturdays? the script will execute two times


    We have to test if this is the fourth week(i.e. the last seven days of the month) and it is Saturday. We need to keep in mind that some months are 30 days, some are 28 and some are 31.


    The test can be either in cron itself or in the script. I prefer to put the test in the script itself. For me I'd run the script from 22-31 and I'd test if the day is Saturday to run it. Maybe create a counter somewhere in a text file to check if the script has run once before or not to avoid two saturdays situation.
    [COLOR=#000000][FONT=verdana] [/FONT][/COLOR]00 22 22-31 * * [COLOR=#000000][FONT=verdana]test 'date +\%a' != Sat || /backup.sh[/FONT][/COLOR]
    


    The above code will work, but it will execute two times if there are two Saturdays in the period 22-31. We have to check for this in the script itself. One way to do it is to have an empty text file as flag with the value 0. if it's changed to 1 then the script has run.

    Here some discussions:

    How to Set up a cronjob On 4th Sunday of every Month? - Page 2 - The UNIX and Linux Forums
    Run a cronjob task every 3rd Sunday? - The macosxhints Forums
    Aix - View topic - cron for 4th sunday every month?
    Certs: GSTRT, GPEN, GCFA, CISM, CRISC, RHCE

    Check out my YouTube channel: https://youtu.be/DRJic8vCodE 


  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    UnixGuy, I should have made it clearer that I was referring to solutions #2 and #3 above more holistically, without looking at exact numbers there. What I meant was that checking the date would have to happen as part of the command sequence executed by cron (either within the invoked script or outside of it) and not as part of cron time parameters (first 5 fields)
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • UnixGuyUnixGuy Mod Posts: 4,564 Mod
    @onesaint & @ChooseLife: true both are correct answers :)
    Certs: GSTRT, GPEN, GCFA, CISM, CRISC, RHCE

    Check out my YouTube channel: https://youtu.be/DRJic8vCodE 


  • log32log32 Users Awaiting Email Confirmation Posts: 217
    Awesome questions & Answers, keep them coming!
  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    ChooseLife wrote: »
    Question: How can you download a file from an HTTP server using bash without netcat/curl/wget/w3m/lynx?
    As a follow-up, here's a somewhat related article:
    Netcat without -e? No Problem!
    which I hope some of you may enjoy reading icon_smile.gif
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    Here's another one. This question, in my opinion, can differentiate between real experience and book knowledge. An experienced sysadmin who has encountered this issue at least once before should have no problem figuring it out. Books, on the other hand, do not teach you this - if they do, surprise me! icon_smile.gif

    Unfortunately, this scenario is not reproducable locally unless I provide instructions that give out the root cause. So ask me questions or ask me to type commands on this pretend system.


    Question: Suppose you are on a production server and are trying to create a new log file. However, you encounter the following behaviour:
    $ echo Test > /var/log/my_new_custom.log
    bash: echo: write error: No space left on device
    $ su
    # echo Test > /var/log/my_new_custom.log
    bash: echo: write error: No space left on device
    

    Your little investigation reveals the following information:
    $ ls -al /var/log
    drwxr-xr-x 18 root              root         4096 May 17 10:24 .
    drwxr-xr-x 12 root              root         4096 May 17 09:40 ..
    
    $ ls -l /var
    drwxr-xr-x 18 root root     4096 May 17 10:24 log
    drwxr-xr-x 10 root root     4096 Mar 17 10:22 spool
    drwxrwxrwt  2 root root     4096 May 17 09:54 tmp
    
    $ df /var
    /dev/sdb1                156185596 42384420 113801176  28% /var
    

    Why is the system complaining about lack of space? What command can you execute to find the root cause of the issue?

    I have a tiny hint for this one, should anyone need it. Another hint is embedded into the question.
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • UnixGuyUnixGuy Mod Posts: 4,564 Mod
    ###

    Interesting problem, I run into it from time to time with servers that run Oracle databases.
    Certs: GSTRT, GPEN, GCFA, CISM, CRISC, RHCE

    Check out my YouTube channel: https://youtu.be/DRJic8vCodE 


  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    UnixGuy wrote: »
    Maybe...
    Of course you know the answer, UnixGuy, I wouldn't doubt it :)
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • paul78paul78 Member Posts: 3,016 ■■■■■■■■■■
    Good one. I pm'd my guess so I don't hog the answer attempts.
  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    UnixGuy wrote: »
    Interesting problem, I run into it from time to time with servers that run Oracle databases.
    I first ran into it with a misconfigured mail server and a bunch of other systems since then
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    paul78 wrote: »
    Good one. I pm'd my guess so I don't hog the answer attempts.
    And you've got it right!
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • onesaintonesaint Member Posts: 801
    When I was first starting to learn Linux, the guy teaching stressed the point of using mv when i couls as opposed to cp because you'll use up the items in question (if I'm right).
    Work in progress: picking up Postgres, elastisearch, redis, Cloudera, & AWS.
    Next up: eventually the RHCE and to start blogging again.

    Control Protocol; my blog of exam notes and IT randomness
  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    onesaint wrote: »
    When I was first starting to learn Linux, the guy teaching stressed the point of using mv when i couls as opposed to cp because you'll use up the items in question (if I'm right).
    Looks like the question was not as tricky as I hoped... Fine, let's consider this one solved icon_smile.gif

    paul78 or onesaint (or anyone else), care to answer this part to finish it up:
    What command can you execute to find the root cause of the issue?
    (UnixGuy did in his initial response)
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • paul78paul78 Member Posts: 3,016 ■■■■■■■■■■
    Hmmm... Not sure I know of top of head but I would probably start with fsck. And then used find -size to find all the small files. Usually there's a bunch of small temp files lying around if its a email or spooler.
  • onesaintonesaint Member Posts: 801
    # df -i
    would give you node info (I just used it the other day when a server went RO for no reason!).


    I've got (maybe an easy) one for you all:

    Let's say I accidentally did an rm -rf on ../httpd/access_log but I still need the file.

    Is it recoverable? If so, how?
    Work in progress: picking up Postgres, elastisearch, redis, Cloudera, & AWS.
    Next up: eventually the RHCE and to start blogging again.

    Control Protocol; my blog of exam notes and IT randomness
  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    Ok, I'll take these two combined as a full answer :)
    onesaint wrote: »
    # df -i
    would give you node info
    paul78 wrote: »
    And then used find -size to find all the small files. Usually there's a bunch of small temp files lying around if its a email or spooler.
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    ChooseLife wrote: »
    Question: Suppose you are on a production server and are trying to create a new log file. However, you encounter the following behaviour:
    $ echo Test > /var/log/my_new_custom.log
    bash: echo: write error: No space left on device
    $ su
    # echo Test > /var/log/my_new_custom.log
    bash: echo: write error: No space left on device
    
    ...
    Why is the system complaining about lack of space? What command can you execute to find the root cause of the issue?
    This question got a fair share of responses (some via PM), so I'll post the answer.

    The system is giving a "No space left on device" error because all of the inodes for the partition have been used up.
    A quick way to confirm that is to do "df -i", which shows inode usage per partition, and then dig deeper by counting files in directories to discover where the inodes are being used up.
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    onesaint wrote: »
    I've got (maybe an easy) one for you all:

    Let's say I accidentally did an rm -rf on ../httpd/access_log but I still need the file.

    Is it recoverable? If so, how?
    Very good question. What filesystem are we talking about here?
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • onesaintonesaint Member Posts: 801
    Great question and answer, ChooseLife.

    To answer your question, my solution is from systems with ext3/4, however the solution is available across many distros making it FS independent.
    Work in progress: picking up Postgres, elastisearch, redis, Cloudera, & AWS.
    Next up: eventually the RHCE and to start blogging again.

    Control Protocol; my blog of exam notes and IT randomness
  • W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    Not sure if this question has been asked but I'll go ahead and ask it.

    I've got a 3TB harware RAID 1 volume. I can view the drive with
    parted -l
    
    but not with
    fdisk -l
    
    . Why is that?
  • ClevernamehereClevernamehere Member Posts: 34 ■■■□□□□□□□
    I'm thinking something to do with fdisk not being able to create partitions over 2TB?
Sign In or Register to comment.