LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-23-2015, 02:49 PM   #1
rmcateer
Member
 
Registered: Oct 2014
Posts: 41

Rep: Reputation: Disabled
bash script-how can user choose how long to run it for?


I am currently writing a bash script to output the statistics of vmstat, iostat and other commands. The script allows the user to type in how long they wish to run it for and how many repetitions.

I have been running stress on Ubuntu with stress -c 2 -t 40s for example and it stresses for 40 seconds. I would like however to run stress in bash and for the user to select how long they want to run stress for and for the system to read this and then exit afterwards.

Does anyone know how to do this? Thanks.
 
Old 02-23-2015, 03:41 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Well, show us your code!
 
Old 02-23-2015, 03:47 PM   #3
rmcateer
Member
 
Registered: Oct 2014
Posts: 41

Original Poster
Rep: Reputation: Disabled
This is part of the code for vmstat/iostat one, which works properly and responds to the user input and then returns to the main menu ok. I would prefer to have the stress input in a different script but what is the syntax for the user to choose how long to run stress for? If I have used vmstat $INT even on its own, the script just freezes.


#!/bin/bash
#
# Script to output system statistics
echo "Enter the number of intervals (seconds) for the sar statistics:"
read int
echo "enter the number of output lines (count) to process:"
read cnt
clear
#set while

while true; do
clear
echo "*******************************"
echo "* Please choose an option *"
echo "*******************************"
echo "* [1] To view process creation statistics *"
echo "* [2] To view I/O and transfer rate statistics *"
echo "* [3] To view paging statistics *"
echo "Press A to quit."
echo "************************"
echo -n "Enter your menu choice [1-3]: "
D=`/bin/date '+%B.%d'`
INT=$int
CNT=$cnt
#Variable to read input from the keyboard.
read mychoice
case $mychoice in
1) echo "process creation statistics";
vmstat $INT $CNT |tee /tmp/sar_proc_stat_$D
echo "This file will be saved to /tmp/sar_pc_stat_$D"
sleep 3 ;;
 
Old 02-23-2015, 09:10 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,021

Rep: Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199
I am not sure I understand the issue? Can you not use your variables with the switches to the command?

Also, please use [code][/code] tags around code and data to make it easier to read
 
  


Reply

Tags
bash, centos7, ubuntu 12.04


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] bash; automatically run user script after startx has completed porphyry5 Programming 5 03-05-2013 12:55 PM
Bash/Perl script - provide list of hosts to choose from and ssh to chosen host loadedmind Programming 4 04-07-2010 01:19 PM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM
Granting root permissions to a bash script than can be run by a user? SirTristan Linux - Newbie 4 06-14-2008 10:29 PM
Getting bash script files to run as root user helptonewbie Programming 5 04-13-2007 09:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration