How to extract .depot file on HPUX? - extract

How can I extract extract a .depot file on HPUX?
The .depot file is a tarred dir stucture, with some of the files gzipped under the same name as original.
Note that my environment is quite limited - I can't have root, I don't have swinstall.
http://forums13.itrc.hp.com/service/forums/questionanswer.do?admit=109447627+1259826031876+28353475&threadId=1143807
At best, the solution should work on Linux too.
I have tried to untar and gunzip -f -r -d -v --suffix= .
But the problem is that the gzipped files have no suffix, so in the end, gzip deletes them.

It was relatively easy:
for f in `find -type f` ; do
mv $f $f.gz
gunzip $f.gz
done

Related

MacOS/Windows - How to extract specific .json file from multiple zips and renaming the .json file as folder it was extracted from

I am dealing with cuckoo sandbox exported data having report.json file under each zip file.
eg > 123456.zip each zip has the file in zipfile/reports/report.json
I have multiple zip files in a folder. I want to have those zip files to be named as zipfilename.json. I have tried many ways but to fail, here's the code I am trying:
#! /bin/bash
mkdir -p "DESTDIR"
for i in *.zip ; do
unzip "$i" $i/reports/report.json -d "DESTDIR"
mv "DESTDIR/reports/report.json" "DESTDIR/$(basename "$i" .zip)_THEFILE"
done
All I get is this output showing that the file does not exist:
(base) s#Sais-MBP Downloads % sh script.sh
Archive: 1959098.zip
caution: filename not matched: 1959098.zip/reports/report.json
mv: rename DESTDIR/THEFILE to DESTDIR/1959098_THEFILE: No such file or directory
Archive: 1959100.zip
caution: filename not matched: 1959100.zip/reports/report.json
mv: rename DESTDIR/THEFILE to DESTDIR/1959100_THEFILE: No such file or directory
Any help is greatly appreciated as I cannot make any progress for the past few days.
okay, I took help from a friend and he gave me the answer to it as I have done the whole script wrong
#! /bin/bash
#
# save this file as test.sh
#
mkdir -p "DESTDIR"
for ZIPFILE in *.zip ; do
NAME="${ZIPFILE%.*}"
mkdir -p "DESTDIR/$NAME"
unzip -j $ZIPFILE reports/report.json -d "DESTDIR/$NAME/"
mv "DESTDIR/$NAME/report.json" "DESTDIR/$NAME.json"
done

How do I access the data in a bucket using gsutil

C:\Users\goura\AppData\Local\Google\Cloud SDK>gsutil cp -r gs://299792458bucket/X
CommandException: Wrong number of arguments for "cp" command.
getting this error
You need to give it a location to copy to probably?
Try:
gsutil cp -r gs://299792458bucket/X .
(be sure you're in a directory that doesn't have a lot of other files in it)

Validating the json files in a folder/sub folder through shell script

find dir1 | grep .json | python -mjson.tool $1 > /dev/null
I am using the above command but this doesn't take the files as inputs. What should i do to check for all the json files in a folder and validate whether its a proper json.
I found this a while back and have been using it:
for j in *.json; do python -mjson.tool "$j" > /dev/null || echo "INVALID $j" >&2; done;
I'm sure it compares similarly to dasho-o's answer, but am including it as another option.
You need to use 'xarg'.
The pipe find/grep will place the file names of the json file to STDIN. You need to create a command line with those file names. This is what xargs does:
find dir1 | grep .json | xargs -L1 python -mjson.tool > /dev/null
Side notes:
Since 'find' has filtering and execution predicates, more compact line can be created
find dir1 -name '*.json' -exec python -mjson.tool '{}' ';'
Also consider using 'jq' as light weight alternative to validating via python.

Find all files with .md extension and execute a command with the file and generate a new file with a name generated through the the md file name

I'm trying to write a shell script to recursively find all files under a directory with the extension .md and execute a command with the .md file and generated new file with the same name but a different extension.
below is the command I'm having but its actually appending the .html to the file instead of replacing .md with .html
find . -name '*.md' -exec markdown-html {} -s
resources/styles/common-custom.css -o {}.html \;
the above command generates a new file "home.md.html" from "home.md" but i want the .md removed. tried different solutions but didn't work
Hi you have to write a small script here, I have given the description how it is going to work, please refer to the comments in the below codes:-
First create a shell script file like convertTohtml.sh and add below codes in it
#!/bin/bash
find . -name '*.md' > filelist.dat
# list down all the file in a temp file
while read file
do
html_file=$( echo "$file" | sed -e 's/\.md//g')
# the above command will store 'home.md' as 'home' to variable 'html_file'
#hence '$html_file.html' equal to 'home.html'
markdown-html $file -s resources/styles/common-custom.css -o $html_file.html
done < filelist.dat
# with while loop read each line from the file. Here each line is a locatin of .md file
rm filelist.dat
#delete the temporary file finally
provide execute permission to your script file like below:-
chmod 777 convertTohtml.sh
Now execute the file:-
./convertTohtml.sh
Below script will work to solve the extension problem.
#!/bin/bash
find . -name '*.md' > filelist.dat
# list down all the file in a temp file
while read file
do
file=`echo ${file%.md}`
#get the filename witout extension
markdown-html $file -s resources/styles/common-custom.css -o $file.html
done < filelist.dat
# with while loop read each line from the file. Here each line is a locatin of .md file
rm filelist.dat
#delete the temporary file finally
If you want to use the output of find multiple times you could try something like this:
find . -name "*.md" -exec sh -c "echo {} && touch {}.foo" \;
Notice the:
sh -c "echo {} && touch {}.foo"
The sh -c will run commands read from the string, then the {} will be replaced with the find output, in this example is first doing an echo {} and if that succeeds && it will then touch {}.foo, in your case this could be like:
find . -name "*.md" -exec sh -c "markdown-html {} -s resources/styles/common-custom.css -o {}.html" \;

Trying to create $now folder and copy .sql files created folders

I have a shell script that I am trying to run every few days that copies .sql database files and moves them into a designated folder appeneded with /$now/. The script executes perfectly, but I am getting a cp: cannot create regular file '/path/to/dir/$now/': No such file or directory.
I know these folders exist because it is showing up when I 'ls -ltr' the directory.
All of my permissions are executable and writable.This has been puzzling me for about a week now and I just cant put a finger on it.
Here is my code:
#!/bin/bash
BACKUP_DIR="/backups/mysql/"
FILE_DIR=/dbase/files/
now=$(date +"%Y_%m_%d")
# setting the input field seperator to newline
IFS=$'\n'
# find db backups and loop over
for file in $(find ${FILE_DIR} -maxdepth 1 -name "*.sql" -type f -exec basename {} \;); do
# create backup directory:
mkdir -p "${BACKUP_DIR}${file%.sql}/${now}"
# copy file over
cp "${FILE_DIR}${file}" "${BACUP_DIR}${file%.sql}/${now}/"
done
Thanks in advance!
Update:
Error I am getting:
+ mkdir -pv /backups/mysql/health/2014_12_04
+ cp /dbase/files/health.sql health/2014_12_04/
cp: cannot create regular file 'health/2014_12_04/': No such file or directory
This is happening for all 9 directories already created
The error was a typo. I was missing the 'K' in $BACKUP_DIR on the cp line. Here is the correct code:
#!/bin/bash
BACKUP_DIR="/backups/mysql/"
FILE_DIR=/dbase/files/
now=$(date +"%Y_%m_%d")
# setting the input field seperator to newline
IFS=$'\n'
# find db backups and loop over
for file in $(find ${FILE_DIR} -maxdepth 1 -name "*.sql" -type f -exec basename {} \;); do
# create backup directory:
mkdir -p "${BACKUP_DIR}${file%.sql}/${now}"
# copy file over
cp "${FILE_DIR}${file}" "${BACKUP_DIR}${file%.sql}/${now}/"
done