Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to find second difference with KornShell (ksh) or Bourne-again shell (Bash) in UNIX?
How can i do this?
Thanks.
If you are looking something like to calculate time taken to do something then take a look at the script below
#!/bin/bash
STARTING_TIME=$(date +%s)
# do something
ENDING_TIME=$(date +%s)
DIFFERENCE=$(( $ENDING_TIME - $STARTING_TIME ))
echo "It took $DIFFERENCE seconds"
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
Improve this question
Using the uprobe example for hooking bash's readline gives one line at a time. What/How should I hook to get multi-line commands?
I tried hooking add_history but that gives me only one line.
Example input:
cat EOF
x
<< EOF
ls \
| grep
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to store the day of currrent date into variable and then use in a IF condition to run specific commands on specific days.
I have used date +'%u' but it's not helping me.
What about this:
day=$(date +'%u')
if [ "$day" -eq "4" ]; then
echo "Today is Thursday";
else
echo "Today is not Thursday"
fi
If you want to refer to the day of the year, change %u to %j, or to %d to get the day of the month.
Of course the variable day could also be inlined.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm try to make a script for checking some ethx.
If the eth is up and connected my script is working
When its not working I have a problem.
RESD=$(ssh -q vmx#$1 cat /sys/class/net/$3/dormant)
I get in RESD the following result:
cat: /sys/class/net/eth3/dormant: Invalid argument
I want to put in RESD now the first letter.
How can I do this?
Thanks
As per the comment above, this what you want to do: RESD=${RESD:0:1}? This is pure bash equivalent of RESD=$(echo $RESD | cut -c1).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
What method can one use to alternate a variable which is dependable by time?
For example, this week var = Office, then next week var = Oncall?
The resulting script will be using crontab to output the contents of var depending on which week it was.
Thanks.
You can use date +%W to check what week number of the year it is (starting Monday).
You can alternate between the two with e.g.
if (( $(date +%W) % 2 ))
then
var=Office
else
var=Oncall
fi
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a unix assignment and What I have isnt working right. It doesnt format like the normal "cal" function.
#!/bin/bash
d=`date '+%Y'`;
$((++d));
calstr=`cal $d`;
echo $calstr;
You don't need the $ in line 2, and you need to wrap the $calstr in double quotes:
#!/bin/bash
d=`date '+%Y'`;
((++d));
calstr=`cal $d`;
echo "$calstr";