Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
Issue: Start the Adaptec Utility in terminal and blink the second hard drive light. Sleep and submit a keystroke to end the blink.
> arcconf identify 1 device 0 1
Controllers found: 1
The specified device is blinking.
Press any key to stop the blinking.
Command: arcconf identify 1 device 0 1
Here are some commands I have tried.
1.) echo -ne '\n' | arcconf identify 1 device 0 1
Result: Starts the program and immediately submits an 'enter'. The utility is stopped before the drive can blink; I'm not sure how to add sleep here.
2.) kill -9 8309
Result: Kills the arcconf process, however, even with the process terminated the drive will forever blink.
3.) echo -ne '\n' > /proc/8309/fd/0
Result: Sends an 'enter' to the process, however, this only prints new lines to the terminal running arcconf and doesn't actually submit a keystroke. Same result with echo "abcd".
How can I start this utility in bash, sleep, and send a keystroke to stop the utility?
Assuming you want to sleep for 5 seconds, try a bash process substitution
arcconf identify 1 device 0 1 < <(sleep 5; echo)
Another more precise option is to use expect
expect <<'END'
spawn arcconf identify 1 device 0 1
expect "Press any key to stop the blinking"
send "\r"
expect eof
END
Use shell statement grouping:
{ printf '\n'; sleep 5; } | arcconf identify 1 device 0 1
The pipe to the program's stdin will stay open until the sleep finishes.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 months ago.
Improve this question
I need this for some stress testing with my CPU. It uses Linux-Debian/Ubuntu OS and I was wondering if there's any way that I could put it under load until it reaches a certain temperature.
Are there any commands, packages or bash scripts for this?
Any help is appreciated!
Download Prime95 from here or use any other CPU-Stress test that works under Debian/Ubuntu.
Get the following package:
sudo apt-get install lm-sensors
Start the sensors in terminal and update continously:
watch sensors
Now start Prime95 or your preferred stress-test and you can see cpu-temp inside terminal. Stop Stress test if cpu-temp exceeds your desired temperature. (modern cpu's are lowering clockspeed or shutting down automatically before damage from overheating is taken)
OR (automatically stopping at a user-specified temp)
Get the following packages:
sudo apt-get install lm-sensors
sudo apt-get install stress
store the following code as bashfile i.e. stresstest.sh and run it with sh /path/to/stresstest.sh
#!/bin/bash
sensors=/usr/bin/sensors
read_temp() {
# get max Packagetemp from lm-sensors
${sensors} | grep 'Package' | awk '{print int($4)}'
}
echo 'Maximum CPU-Temperature:'
# insert tjMax manually
read tjMax
echo 'Workers for testing:'
# more workers cause higher load on the cpu
read workers
echo 'starting stress-test.'
pckgMax=$( read_temp )
while [ $tjMax -gt $pckgMax ]
do
# update Packagetemp
pckgMax=$( read_temp )
# do 10sec stress-test
# if you discover high temperature overhead, try lowering the --timeout
stress --cpu ${workers} --timeout 10
done
echo 'reached tjMax.'
echo 'stopping stress-test.'
# kill this script and all running sub-processes
kill -- -0
I don't know of an existing software package (other than prime95 for max heating), but it's relatively easy to create loops with differing amounts of heat, like awk 'BEGIN{for(i=0;i<100000000;i++){}}' keeps a CPU busy for a while making some heat.
See How to write x86 assembly code to check the effect of temperature on the performance of the processor for some suggestions on creating loops that heat the CPU more vs. less.
To hit a target temperature, you'll need to write some code to implement control loop that reads the temperature (and the direction it's trending) and adjusts the load by starting/stopping threads, or changing up how power-intensive each thread is. Without this feedback, you won't consistently hit a given CPU temperature; the actual temperature for an fixed workload will depend on ambient temp, how dusty your heat-sink is, and how the BIOS manages your fan speeds, etc.
Perhaps your CPU-heating threads could branch on a global atomic variable in an outer loop, so you can change what work they do by changing a variable. e.g. 2 FMAs per clock, 1 FMA per clock, FMAs bottlenecked by latency (so 1 per 4 clocks), or just integer work, or a loop just running pause instructions, so it does the minimum. Or 256-bit vs. 128-bit vs. scalar.
Perhaps also changing your EPP setting (on Intel Skylake or newer) with sudo sh -c 'for i in /sys/devices/system/cpu/cpufreq/policy[0-9]*/energy_performance_preference;do echo performance > "$i";done' or balance_performance or balance_power (emphasize power-saving); these may affect what turbo clock speeds your CPU chooses to run at.
Read the temperature with lm-sensors, or by reading from the "coretemp" kernel driver directly on modern x86 hardware, e.g. /sys/class/hwmon/hwmon3/temp1_input reads as 36000 for 36 degrees C.
$ grep . /sys/class/hwmon/hwmon3/*
/sys/class/hwmon/hwmon3/name:coretemp
/sys/class/hwmon/hwmon3/temp1_input:36000
/sys/class/hwmon/hwmon3/temp1_label:Package id 0
/sys/class/hwmon/hwmon3/temp2_input:35000
/sys/class/hwmon/hwmon3/temp2_label:Core 0
/sys/class/hwmon/hwmon3/temp5_input:33000
/sys/class/hwmon/hwmon3/temp5_label:Core 3
I'm not sure if the temperature is available directly to user-space without the kernel's help, e.g. via CPUID, on Intel or AMD.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I was currently controlling this through an uptime.
The computer restarts if uptime is greater than 1h.
But I do not know how to control if the computer is one day on or more, because currently I only control the hours.
Is it possible to control days, hours and minutes with uptime?
I need to restart the computer when the power on time is greater than 1h.
If the time is 1 day and 0 hours gives failure.
Sorry for my explanation, it is a script that does a series of things and alfinal exists this function that is responsible for controlling this parameter.
thanks for reading me
Not sure I quite understand your issue.
If you want your computer to ALWAYS reboot after a specific amount of time, which is very unusual, then use cron. Add this to /etc/crontab (alternatively, if there is a /etc/cron.d directory on your machine, you can also create a file /etc/cron.d/reboot with this content) :
#reboot root sleep 1800; /sbin/reboot
(adapt reboot's path to match your system; 1800 is the number of seconds for 30 minutes, change it to whatever delay you need)
On the other hand, you may be writing a script that will reboot your server, and you may want to keep it from working if it is run before 30 minutes of uptime (which makes more sense).
Then, I understand you have difficulties parsing the result of uptime and you should use /proc/uptime which gives your uptime in seconds:
#!/bin/sh
not_before=1800 # Number of seconds - adapt to your needs
uptime=$(cut -d . -f 1 /proc/uptime)
[ "$uptime" -ge "$not_before" ] && exec reboot
echo "Sorry, only $uptime s of uptime; you must wait $((not_before - uptime)) seconds" >&2
exit 1
If you want to do it in a script, use the result of uptime | grep " day"to determine whether to execute things (in anifcondition), then do anything you want inside theif`.
Make that script executable and put it in crontab to run every 5min or so.
More information on Cron: https://wiki.archlinux.org/index.php/Cron
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I have couple of machines as shown below which are running Ubuntu 12.04 and I need to find out the process name along with its pid whose CPU usage is greater than 70%.
Below are the machines as an example -
machineA
machineB
machineC
machineD
I need to have my shell script which can run periodically every 15 minutes and check whether any of the above machines has CPU usage greater than 70%. If there are any machines which are having CPU usage as greater than 70%, then send out an email with the machine name and the process name along with it's id.
I will be running my shell script from machineX and I have passwordless ssh key setup for user david from machineX to all the above machines.
What is the best way to do all these kind of monitoring?
I have below command which can get me PID, %CPU and COMMAND name of the process whose CPU usage is greater than 70%.
ps aux --sort=-%cpu | awk 'NR==1{print $2,$3,$11}NR>1{if($3>=70) print $2,$3,$11}'
Not sure how to fully automate this process?
Hey men you are doing something wrong there, the cpu there its peak cpu in the current execution gap. That means that in the next second this proccess may not be eating any resources. Its better to use a different way to catch up cpu hungry proccess. My prefered way its by cpu time. Have a look on this example:
panos#wintermute:~$ ps xafu
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2 0.0 0.0 0 0 ? S 18:53 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 18:53 0:00 \_ [ksoftirqd/
root 5 0.0 0.0 0 0 ? S< 18:53 0:00 \_ [kworker/0:
root 7 0.0 0.0 0 0 ? S 18:53 0:02 \_ [rcu_sched]
TIME: is the cpu time a proccess has bean eat. normal proccess dont need to eat much cpu proccess. So by creating a simple shell script with a small loop you could gather the information you need. The shell script could looked like:
#!/bin/sh
date
for i in "a b c d" ; do
echo machine${i}
ssh machine${i} ps xau|awk 'NR==1{print $2,$10,$11}NR>1{if($10>=5) print $2,$10,$11}'
echo -- --
done
exit
That will match any proccess that has bean eat 5 minutes of cpu
AWK does row-oriented editing (and a bunch of other stuff too).
A block of statements enclosed in brackets {} will be executed on each row of input.This behaviour may be limited by prefixing the block with a condition (in ordinary C syntax)
NR==1 {} means that block will be executed on a first input row. In the example above fields 2, 10 and 11 from the first input row will be printed on a single row.
NR>1 {} means that block will be executed for each row after the first one.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I'm writing a script that does daily snapshots of users' home directories. First I do a dry run using:
rsync -azvrn --out-format="%M %f" source/dir dest/dir
and then the actual rsync operation (by removing the -n option).
I'm trying to parse the output of the dry run. Specifically, I'm interested in learning the exact cause of the rsync error (if one occurred). Does anyone know of
The most common rsync errors and their codes?
A link to a comprehensive rsync error code page?
Most importantly, rsync (at least on CentOs 5) does not return an error code. Rather it displays the errors internally and returns with 0. Like thus:
sending incremental file list
rsync: link_stat "/data/users/gary/testdi" failed: No such file or directory (2)
sent 18 bytes received 12 bytes 60.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]
Has anyone had to parse rsync errors and have a suggestion on how to store the rsync return state(s)? I believe, when transferring multiple files, that errors may be raised on a per file basis and are collected at the end as shown on the last line of code above.
Per the rsync "man" page, here are the error codes it could return and what they mean. If you're scripting it in bash, you could look at $?
0 Success
1 Syntax or usage error
2 Protocol incompatibility
3 Errors selecting input/output files, dirs
4 Requested action not supported: an attempt was made to manipulate 64-bit
files on a platform that cannot support them; or an option was specified
that is supported by the client and not by the server.
5 Error starting client-server protocol
6 Daemon unable to append to log-file
10 Error in socket I/O
11 Error in file I/O
12 Error in rsync protocol data stream
13 Errors with program diagnostics
14 Error in IPC code
20 Received SIGUSR1 or SIGINT
21 Some error returned by waitpid()
22 Error allocating core memory buffers
23 Partial transfer due to error
24 Partial transfer due to vanished source files
25 The --max-delete limit stopped deletions
30 Timeout in data send/receive
35 Timeout waiting for daemon connection
I've never seen a comprehensive "most common errors" list but I'm betting error code 1 would be at the top.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I setup a CentOS 6.3 setup, on which the console loglevel is set to 4, and default log level is set to 4. I know I can change the default console log level using the following steps:
cat /proc/sys/kernel/printk
4 4 1 7
echo 5 > /proc/sys/kernel/printk
cat /proc/sys/kernel/printk
5 4 1 7
However, upon reboot, the console log level reverts back to the original value. Do I need to recompile the kernel, or is there a way I can get the changed value to be persistent across reboot.
Do I need to recompile the kernel,
No.
or is there a way I can get the changed value to be persistent across reboot.
Yes.
Use the kernel command line parameter loglevel:
loglevel= All Kernel Messages with a loglevel smaller than the
console loglevel will be printed to the console. It can
also be changed with klogd or other programs. The
loglevels are defined as follows:
0 (KERN_EMERG) system is unusable
1 (KERN_ALERT) action must be taken immediately
2 (KERN_CRIT) critical conditions
3 (KERN_ERR) error conditions
4 (KERN_WARNING) warning conditions
5 (KERN_NOTICE) normal but significant condition
6 (KERN_INFO) informational
7 (KERN_DEBUG) debug-level messages
The entire list of parameters possible on the kernel command line are in the Linux/Documentation/kernel-parameters.txt file in the source tree.
Depending on your bootloader (e.g. Grub or U-Boot), you will have to edit text to add this new parameter to the command line. Use cat /proc/cmdline to view the kernel command line used for the previous boot.
Addendum
To display everything, the number supplied for the loglevel parameter would have be be greater than KERN_DEBUG.
That is, you would have to specify loglevel=8.
Or simply use the ignore_loglevel parameter to display all kernel messages.