Shell script to calculate the total space consumed by a user by file-size

I’m working with a small bash code which is working fine but i’m just looking if there is better way to formulate this, In this code i’m looking for the Files between year 2002 and 2018 on the 7th column.

Below is the working code,

Script:

#!/bin/bash # scriptName: Ftpcal.sh FILE="/home/pygo/Cyberark/ftplogs_3" AWK="/bin/awk" GREP="/bin/grep" USERS="`"$  AWK" '$  7 >= "2002" && $  7 <= "2018"' $  FILE | "$  AWK" '{print $  3}' | sort -u`" for user in $  USERS; do echo "User $  user " | tr -d "\n"; "$  AWK" '$  7 >= "2002" && $  7 <= "2018"' "$  FILE" | "$  GREP" "$  user" | "$  AWK" '{ total += $  4}; END { print "Total Space consumed: "  total/1024/1024/1024 "GB"}'; done | column -t echo "" echo "==============================================================" "$  AWK" '$  7 >= "2002" && $  7 <= "2018"' "$  FILE" | "$  AWK" '{ total += $  4}; END { print "Total Space consumed by All Users: "  total/1024/1024/1024 "GB"}'; echo "" 

Actual data Result:

$   sh Ftpcal.sh  User  16871                   Total  Space  consumed:  0.0905161GB User  253758                  Total  Space  consumed:  0.0750855GB User  34130                   Total  Space  consumed:  3.52537GB User  36640                   Total  Space  consumed:  0.55393GB User  8490                    Total  Space  consumed:  3.70858GB User  tx-am                   Total  Space  consumed:  0.18992GB User  tx-ffv                  Total  Space  consumed:  0.183137GB User  tx-ttv                  Total  Space  consumed:  17.2371GB User  tx-st                   Total  Space  consumed:  0.201205GB User  tx-ti                   Total  Space  consumed:  58.9704GB User  tx-tts                 Total  Space  consumed:  0.0762068GB  ------------ snipped output -------------- ============================================================== Total Space consumed by All Users: 255.368GB 

Sample data:

-rw-r--r-- 1 34130 14063436 Aug 15  2002 /current/focus-del/files/from_fix.v.gz -rw-r--r-- 1 34130 14060876 Jul 12  2007 /current/focus-del/files/from1_fix.v.gz -rw-r--r-- 1 34130 58668461 Feb 23  2006 /current/focus-del/files/from_1.tar.gz -rw-r--r-- 1 34130 14069343 Aug  7  20017 /current/focus-del/files/from_tm_fix.v.gz -rw-r--r-- 1 34130 38179000 Dec  7  20016 /current/focus-del/files/from_tm.gds.gz -rw-r--r-- 1 34130 15157902 Nov 22  20015 /current/focus-del/files/from_for.tar.gz -rw-r--r-- 1 34130 97986560 Nov  4  20015 /current/focus-del/files/from_layout.tar 

Sample Result:

$   sh Ftp_cal.sh User  34130  Total  Space  consumed:  0.0808321GB  ============================================================== Total Space consumed by All Users: 0.0808321GB 

I’m okay with any better approach as a review process to make it more robust.

Thanks.

how to calculate hash rate of your rig?

First going the easy way, I would use any online calculator but most of these mining calculators require the hash rate of my device. I am unable to find a suitable answer or a guide to easily compute this value for any device given its configurations. Will that be possible?

Scenario:

When I go to these online calculator sites, they again cross question me about the hash rate/ hashing power. I need to determine this value and feed in to these sites so that I can get the desired result. (e.g. cryptocompare.com). I want to know whether it is easy to calculate these values with some information about your machine like the processor, GPUs and all, how much time I am gonna run it. I know the calculator sites need the power input of the device.

Calculate mean of vector primitive numerical values generically

I’m trying to write a generic mean function for all values within an Vector of generic numerical primitive type.

Could the following implementation be possible more efficient, yet still generic enough for all the possible numerical primitives?

Is the num crate really needed?

extern crate num; use std::iter::Sum; use std::ops::Div;  fn mean<'a, T, U>(values: &'a [T]) -> U::Output     where T: Sum<&'a T> + num::ToPrimitive,           U: num::NumCast + Div {     U::from(values.iter().sum::<T>()).unwrap() / U::from(values.len()).unwrap() }  fn main() {     let arr_i32: Vec<i32> = vec![1, 2, 5];     let arr_f32: Vec<f32> = vec![1.1, 2.2, 5.5];     println!("Mean of ({:?}) is: {}", arr_i32, mean::<_, f32>(&arr_i32));     println!("Mean of ({:?}) is: {}", arr_f32, mean::<_, f32>(&arr_f32)); } 

Calculate direction vector given variable hypotenuse in orbital path

enter image description here

In a Unity 3D game I’m trying to make an object (D) orbit another object (B) and draw a ray between another object positioned above the object being orbited (A) and the orbiting object, essentially describing a triangle (or cone, given time + orbit speed):

The object conforms to a hilly terrain (moves up or down from height B as it orbits) via some unrelated code, however, this sometimes means it is positioned further away than max length, for example if it travels down a steep valley or up a steep hill higher than A.

The difficulty I’m having is calculating the vector to the furthest point on the terrain allowed by max length from transform A. To put it another way – in the illustration above the final direction line is the max length line rotated around A until it hits the terrain, this is what I’m after regardless of the height or angle of the terrain.

My trigonometry is pretty basic but I thought calculating the angle from the tangent of AC and AB then multiplying its quaternion by the directional vector (c – a) would give the right direction from A:

private void Update() {     transform.RotateAround(transformB.position, Vector3.up, rotSpeed * Time.deltaTime);      if (Physics.Raycast(transform.position, -transform.up, out hit, 100))     {         float angleDeg = Mathf.Atan2(transformA.position.y,              Vector3.Distance(hit.point, transformA.position)) * Mathf.Rad2Deg;          Quaternion q = Quaternion.AngleAxis(angleDeg, Vector3.left);          Vector3 dir = q * (new Vector3(hit.point.x, transformA.position.y,              hit.point.z) - transformA.position);          Debug.DrawRay(firingTransform.position, dir, Color.green, 0.1f);      } } 

It seems to work correctly for only half of the orbit:

enter image description here

I’ve tried various vectors for Quaternion.AngleAxis axis parameter.

SQL beginner trying to calculate total time in minutes; need help with WHERE syntax error

I’m trying to calculate the total minutes employees were on a system. The data, stored as ‘Action’ looks something like below. Note that employees log on and off multiple times a day.

|---------------------|------------------|------------------------| |         empid       |      action      |         log_date       |  |---------------------|------------------|------------------------| |          a1         |         ON       |2019-01-01T07:00:00.000Z| |---------------------|------------------|------------------------| |          a1         |         OFF      |2019-01-01T07:30:00.000Z| |---------------------|------------------|------------------------| |          a1         |         ON       |2019-01-01T08:30:00.000Z| |---------------------|------------------|------------------------| |          a1         |         OFF      |2019-01-01T11:30:00.000Z| |---------------------|------------------|------------------------| |          a1         |         ON       |2019-01-01T12:30:00.000Z| |---------------------|------------------|------------------------| |          a1         |         OFF      |2019-01-01T12:45:00.000Z| |---------------------|------------------|------------------------| |          a2         |         ON       |2019-01-01T08:45:00.000Z| |---------------------|------------------|------------------------| |          a2         |         OFF      |2019-01-01T09:15:00.000Z| |---------------------|------------------|------------------------| |          a2         |         ON       |2019-01-01T10:00:00.000Z| |---------------------|------------------|------------------------| |          a2         |         OFF      |2019-01-01T11:45:00.000Z| |---------------------|------------------|------------------------| 

Below is the SQL query code that I have been working on so far, but it’s returning ‘Query Error: error: syntax error at or near “WHERE”‘.

SELECT e.empid, CAST(e.log_date AS DATE) AS date, SUM(DATEPART(MINUTE, CAST(e.log_date - s.log_date AS TIME))) AS work_minutes FROM (SELECT empid, log_date       FROM Activity       WHERE action = 'ON') AS s JOIN (SELECT empid       FROM Activity       WHERE action = 'OFF') AS e ON e.empid = s.empid WHERE e.log_date = (SELECT log_date                     FROM Activity                     LIMIT 1                     WHERE empid = e.empid                     AND log_date > s.log_date) GROUP BY e.empid, CAST(e.log_date AS DATE); 

What seems to be the problem? I want the query result to look something like this:

|---------------------|------------------|------------------------| |         empid       |        date      |      work_minutes      |  |---------------------|------------------|------------------------| |          a1         |    2019-01-01    |        100 minutes     | |---------------------|------------------|------------------------| |          b2         |    2019-01-01    |        150 minutes     | |---------------------|------------------|------------------------| 

(work_minutes values above are random)

Any help will be greatly appreciated. Thank you!

Calculate makespan of job shop solution?

I have a job shop problem with n jobs and m machines, a job shop means that not all jobs have to go through every machine.

Here’s an example of a solution to a job shop problem :

enter image description here

The matrix defines 3 jobs x 4 machines, with the values being processing times. The order of jobs matters, the whole problem has 3! = 6 possible solutions, which are the permutations of 3 jobs.

But I am only looking to calculate the makespan of every solution. The third job for example has a processing time of 0 on machine 1. This not only means no precedency constraint for J3 x M2, but it means it won’t obey priority constraint either.

Each machine can never be idle at any time, unless forced to because of precedency constraints.

So Job1 x Machine 1 runs for 10 units, then Job2 x Machine 1 for 15, and so on, making the shortest timespan for this solution 10 + 15 + 15 + 20.

enter image description here

I’m trying to think of an algorithm that takes the matrix as input, and outputs minimum possible makespan for that specific matrix.

A matrix means that higher jobs always take priority, unless a job has 0 processing time for a specific machine, and the following machine is available. Just like in the example where Job 3 is running concurrently with Job 1 because it doesn’t have to wait for it as Machine 2 is available.

How do you calculate CR for running battles?

I am creating an encounter for a game I am DMing and am wondering how you calculate CR for a running battle. What I mean by this is that characters will be fleeing through a zombie infested town, with zombies popping up at regular intervals(every 2-3 rounds).

Theoretically, the battle would never stop, so it’s effectively one encounter, but I don’t think standard CR calculations would work. 15 CR 1 monsters at once is a lot harder than 15 CR 1 monsters in groups of 1-2 in a steady stream.

Any guidelines on how to calculate an appropriate CR in order to balance this?