Skip to main content
Markup
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

I'm currently a bit confused regarding arguments and parameters for a question.

I currently have to accept the log filename as a parameter (For example, /var/log/secure-/var/log/secure-<yyyymmdd>) but default to /var/log/secure/var/log/secure if no arguments are given.

How do I accept the log filename as a parameter? I think it might be the phrasing of the question, but I don't quite get what it means.

This is a snippet of the current code I have done so far before this question:

#!/bin/bash
grep " su: " /var/log/secure | while read -r abc; do   
echo "$abc"
done

For the 2nd part, I have to create a function that exits with code 2  (I'm working on that currently) and afterwards, call that function if a filename is passed but the file doesn't exist. Would I do something like this? It feels wrong but not sure where.

IF [ -d /var/log/secure ]
then

else
runfunction

I'm currently a bit confused regarding arguments and parameters for a question.

I currently have to accept the log filename as a parameter (For example, /var/log/secure-) but default to /var/log/secure if no arguments are given.

How do I accept the log filename as a parameter? I think it might be the phrasing of the question, but I don't quite get what it means.

This is a snippet of the current code I have done so far before this question:

#!/bin/bash
grep " su: " /var/log/secure | while read -r abc; do   
echo "$abc"
done

For the 2nd part, I have to create a function that exits with code 2(I'm working on that currently) and afterwards, call that function if a filename is passed but the file doesn't exist. Would I do something like this? It feels wrong but not sure where.

IF [ -d /var/log/secure ]
then

else
runfunction

I'm currently a bit confused regarding arguments and parameters for a question.

I currently have to accept the log filename as a parameter (For example, /var/log/secure-<yyyymmdd>) but default to /var/log/secure if no arguments are given.

How do I accept the log filename as a parameter? I think it might be the phrasing of the question, but I don't quite get what it means.

This is a snippet of the current code I have done so far before this question:

#!/bin/bash
grep " su: " /var/log/secure | while read -r abc; do   
echo "$abc"
done

For the 2nd part, I have to create a function that exits with code 2  (I'm working on that currently) and afterwards, call that function if a filename is passed but the file doesn't exist. Would I do something like this? It feels wrong but not sure where.

IF [ -d /var/log/secure ]
then

else
runfunction
Source Link

Accepting logfile as parameter and calling a function if filename is passed but file doesn't exist

I'm currently a bit confused regarding arguments and parameters for a question.

I currently have to accept the log filename as a parameter (For example, /var/log/secure-) but default to /var/log/secure if no arguments are given.

How do I accept the log filename as a parameter? I think it might be the phrasing of the question, but I don't quite get what it means.

This is a snippet of the current code I have done so far before this question:

#!/bin/bash
grep " su: " /var/log/secure | while read -r abc; do   
echo "$abc"
done

For the 2nd part, I have to create a function that exits with code 2(I'm working on that currently) and afterwards, call that function if a filename is passed but the file doesn't exist. Would I do something like this? It feels wrong but not sure where.

IF [ -d /var/log/secure ]
then

else
runfunction