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
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 6 years ago.
Improve this question
I installed openstack via devstack on Ubuntu 14.04. I have got 8 gb of ram on my computer and i have created around 8 VM's which i don't use simultaneously as I use the VM differently.
Now i cannot create any more VM's. I get an error message
No Valid Host was found.
there are not enough hosts available.
Can someone advice what should i do?
Since you say that this is a devstack installation, I'm assuming that you aren't running this in a production environment. Openstack allows users to bump up their over-subscription ratio for the RAM. By default, it is kept at 1.5 times the physical RAM available in the machine. Hence, it should be 12 Gb of usable memory. To change the subscription ratio:
sudo vim /etc/nova/nova.conf
#Add these two lines
ram_allocation_ratio=2
cpu_allocation_ratio=20 # Default value here is 16
These values are just a rough estimate. Change the values around to make them work for your environment. Restart the Devstack.
To check if the changes were made, log into mysql (or whichever DB is supporting devstack) and check:
mysql> use nova;
mysql> select * from compute_nodes \G;
*************************** 1. row ***************************
created_at: 2015-09-25 13:52:55
updated_at: 2016-02-03 18:32:49
deleted_at: NULL
id: 1
service_id: 7
vcpus: 8
memory_mb: 12007
local_gb: 446
vcpus_used: 6
memory_mb_used: 8832
local_gb_used: 80
hypervisor_type: QEMU
disk_available_least: 240
free_ram_mb: 3175
free_disk_gb: 366
current_workload: 0
running_vms: 4
pci_stats: NULL
metrics: []
.....
1 row in set (0.00 sec)
The Scheduler looks at the free_ram_mb. If you have a free_ram_mb of 3175 and if you want to run a new m1.medium instance with 4096M of memory, the Scheduler will end up with this message in the logs:
WARNING nova.scheduler.manager Failed to schedule_run_instance: No valid host was found.
Hence, make sure to keep an eye out for those when starting a new VM after making those changes.
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.
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 10 years ago.
Improve this question
I have the following into a crontab and have 7 of these...at range of 15 minutes between one and the other:
50 8 * * * wget -q -O - http://domain.com/path/to/script.php?xxx=3
this script calls mysql, selects every record from a table, does something and updates a certain value...
while usually this script requires about +5minutes to end...and 2 or 3 disappear from running processes...other 3 or 4 do not...it seems they overlap
7020 root 0.0 % wget -q -O - http://domain.com/path/to/script.php?xxx=3
now, can be a priority problem? how to set a priority into crontab (with nice?) ? how priority manages the execution time? with highest priority the process exits before?
if i do mysql > SHOW FULL PROCESSLIST\G
they seem are yet running after 3 hours !
and also...during these sql processes the tables are readable and if not, how to avoid? the pages are served more slowly as usual